diff options
| author | Anhgelus Morhtuuzh <anhgelus@anhgelus.world> | 2024-12-10 19:55:05 +0100 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <anhgelus@anhgelus.world> | 2024-12-10 19:55:05 +0100 |
| commit | a5955c32fb3b22e37769df49196ddab7b7d53b7d (patch) | |
| tree | a1c8f7eca8e87b3c3d836ff3effa2f6a2183278d | |
| parent | 9b6819f25fc860ea1c2dc84b61b7576b73aaa78c (diff) | |
feat(custom): support links
| -rw-r--r-- | data.go | 40 | ||||
| -rw-r--r-- | scss/main.scss | 7 | ||||
| -rw-r--r-- | templates/page/custom_page.gohtml | 4 |
3 files changed, 45 insertions, 6 deletions
@@ -2,6 +2,7 @@ package main import ( "encoding/json" + "fmt" "github.com/anhgelus/golatt" "html/template" "log/slog" @@ -16,6 +17,7 @@ const ( ParagraphContentType = "paragraph" ListContentType = "list" OrderedListContentType = "ordered_list" + ButtonsContentType = "links" ) type ConfigData interface { @@ -172,7 +174,15 @@ func (p *CustomPage) GetBackground() template.CSS { return p.Color.GetBackground() } -func (c *CustomContent) Get() template.HTML { +func (p *CustomPage) GetContent() template.HTML { + var res template.HTML + for _, c := range p.Content { + res += c.Get(p) + } + return res +} + +func (c *CustomContent) Get(p *CustomPage) template.HTML { if c.Type == TitleContentType { return template.HTML("<h2>" + c.Content + "</h2>") } else if c.Type == SubtitleContentType { @@ -191,12 +201,36 @@ func (c *CustomContent) Get() template.HTML { } else if c.Type == OrderedListContentType { v := "" for _, s := range strings.Split(c.Content, "--") { - if len(strings.Trim(s, " ")) == 0 { + if len(strings.TrimSpace(s)) == 0 { continue } - v += "<li>" + strings.Trim(s, " ") + "</li>" + v += "<li>" + strings.TrimSpace(s) + "</li>" } return template.HTML("<ol>" + v + "</ol>") + } else if c.Type == ButtonsContentType { + // [Bonsoir](/hello) -- [Bonjour](/not_hello) + v := "" + for _, s := range strings.Split(c.Content, "--") { + if len(strings.TrimSpace(s)) == 0 { + continue + } + sp := strings.Split(s, "](") + if len(sp) != 2 { + slog.Warn("Invalid button", "s", s) + continue + } + url := strings.TrimSpace(sp[1]) + v += fmt.Sprintf( + `<div class="link"><a href="%s">%s</a></div>`, + url[:len(url)-1], + strings.TrimSpace(sp[0])[1:], + ) + } + return template.HTML(fmt.Sprintf( + `<nav class="links" style="%s">%s</nav>`, + p.Color.Button.GetBackground()+p.Color.Button.GetTextColor(), + v, + )) } slog.Warn("Unknown type", "type", c.Type, "value", c.Content) return "" diff --git a/scss/main.scss b/scss/main.scss index 6c1f316..bef8c81 100644 --- a/scss/main.scss +++ b/scss/main.scss @@ -247,4 +247,11 @@ h4 { & ul { list-style: disc inside; } + & .links { + margin-top: 1rem; + margin-bottom: 1rem; + &:last-child { + margin-bottom: 0; + } + } } diff --git a/templates/page/custom_page.gohtml b/templates/page/custom_page.gohtml index 4cb8078..83a4983 100644 --- a/templates/page/custom_page.gohtml +++ b/templates/page/custom_page.gohtml @@ -6,8 +6,6 @@ <a href="/">Home</a> </nav> </div> - {{ range $content := .Content }} - {{ .Get }} - {{ end }} + {{ .GetContent }} </main> {{end}} |
