Add option for "link" in webring plugin

This commit is contained in:
Jan-Lukas Else 2023-01-03 18:26:27 +01:00
parent 4b9440443b
commit 7ac9a5db0e
2 changed files with 14 additions and 3 deletions

View File

@ -54,7 +54,9 @@ You can add webring links like this:
```yaml ```yaml
config: config:
default: # Name of the blog default: # Name of the blog
- title: Webring # Title to show for the webring - title: Webring # Title to show for the webring (required)
# At least one of link, prev or next is required
link: https://example.org/ # Link to the webring
prev: https://example.com/ # Link to previous webring site prev: https://example.com/ # Link to previous webring site
next: https://example.net/ # Link to next webring site next: https://example.net/ # Link to next webring site
``` ```

View File

@ -46,17 +46,26 @@ func (p *plugin) Render(hb *htmlbuilder.HtmlBuilder, t plugintypes.RenderType, d
for _, webringAny := range blogWebrings { for _, webringAny := range blogWebrings {
if webring, ok := webringAny.(map[string]any); ok { if webring, ok := webringAny.(map[string]any); ok {
title, titleOk := unwrapToString(webring["title"]) title, titleOk := unwrapToString(webring["title"])
link, linkOk := unwrapToString(webring["link"])
prev, prevOk := unwrapToString(webring["prev"]) prev, prevOk := unwrapToString(webring["prev"])
next, nextOk := unwrapToString(webring["next"]) next, nextOk := unwrapToString(webring["next"])
if titleOk && (prevOk || nextOk) { if titleOk && (linkOk || prevOk || nextOk) {
hb.WriteElementOpen("p") hb.WriteElementOpen("p")
if prevOk { if prevOk {
hb.WriteElementOpen("a", "href", prev) hb.WriteElementOpen("a", "href", prev)
hb.WriteEscaped("←") hb.WriteEscaped("←")
hb.WriteElementClose("a") hb.WriteElementClose("a")
hb.WriteEscaped(" ")
}
if linkOk {
hb.WriteElementOpen("a", "href", link)
}
hb.WriteEscaped(title)
if linkOk {
hb.WriteElementClose("a")
} }
hb.WriteEscaped(" " + title + " ")
if nextOk { if nextOk {
hb.WriteEscaped(" ")
hb.WriteElementOpen("a", "href", next) hb.WriteElementOpen("a", "href", next)
hb.WriteEscaped("→") hb.WriteEscaped("→")
hb.WriteElementClose("a") hb.WriteElementClose("a")