From e379601ec1f1ca70f955f7ea9dd07775fb4da93b Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Tue, 10 Dec 2024 19:13:44 +0100 Subject: [PATCH] fix(custom): missing method for new config --- data.go | 53 +++++++++++++++++++++++++++++++++++++++++------------ main.go | 1 + schema.json | 2 +- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/data.go b/data.go index f809e3f..ad6fcea 100644 --- a/data.go +++ b/data.go @@ -18,6 +18,12 @@ const ( OrderedListContentType = "ordered_list" ) +type ConfigData interface { + GetTextColor() template.CSS + GetBackground() template.CSS + GetBackgroundImage() template.CSS +} + type Config struct { Image string `json:"image"` Description string `json:"description"` @@ -76,15 +82,7 @@ type Legal struct { } func (c *Config) GetBackground() template.CSS { - bg := c.Color.Background - css := "background: " + bg.Type + "-gradient(" - if bg.Type == "linear" { - css += strconv.Itoa(int(bg.Angle)) + "deg," - } - for _, c := range bg.Colors { - css += c.Color + " " + strconv.Itoa(int(c.Position)) + "%," - } - return template.CSS(css[:len(css)-1] + ");") + return c.Color.GetBackground() } func (c *Config) GetBackgroundImage() template.CSS { @@ -115,6 +113,7 @@ type Content interface { func (c *Config) LoadCustomPages() ([]*CustomPage, error) { if c.CustomPages == nil { + println("null") return nil, nil } var pages []*CustomPage @@ -123,12 +122,12 @@ func (c *Config) LoadCustomPages() ([]*CustomPage, error) { if err != nil { return nil, err } - var p *CustomPage - err = json.Unmarshal(b, p) + var p CustomPage + err = json.Unmarshal(b, &p) if err != nil { return nil, err } - pages = append(pages, p) + pages = append(pages, &p) } return pages, nil } @@ -137,6 +136,18 @@ func (t *Color) GetTextColor() template.CSS { return template.CSS("--text-color: " + t.Text + ";") } +func (t *Color) GetBackground() template.CSS { + bg := t.Background + css := "background: " + bg.Type + "-gradient(" + if bg.Type == "linear" { + css += strconv.Itoa(int(bg.Angle)) + "deg," + } + for _, c := range bg.Colors { + css += c.Color + " " + strconv.Itoa(int(c.Position)) + "%," + } + return template.CSS(css[:len(css)-1] + ");") +} + func (b *ButtonColor) GetTextColor() template.CSS { return template.CSS("--text-color: " + b.Text + ";--text-color-hover: " + b.TextHover + ";") } @@ -149,6 +160,18 @@ func (t *Color) GetTagColor() template.CSS { return template.CSS("--tag-hover: " + t.TagHover + ";") } +func (p *CustomPage) GetTextColor() template.CSS { + return p.Color.GetTextColor() +} + +func (p *CustomPage) GetBackgroundImage() template.CSS { + return template.CSS("--background-image: url(" + golatt.GetStaticPath(p.Image) + ");") +} + +func (p *CustomPage) GetBackground() template.CSS { + return p.Color.GetBackground() +} + func (c *CustomContent) Get() template.HTML { if c.Type == TitleContentType { return template.HTML("

" + c.Content + "

") @@ -159,12 +182,18 @@ func (c *CustomContent) Get() template.HTML { } else if c.Type == ListContentType { v := "" for _, s := range strings.Split(c.Content, "--") { + if len(strings.Trim(s, " ")) == 0 { + continue + } v += "
  • " + strings.Trim(s, " ") + "
  • " } return template.HTML("") } else if c.Type == OrderedListContentType { v := "" for _, s := range strings.Split(c.Content, "--") { + if len(strings.Trim(s, " ")) == 0 { + continue + } v += "
  • " + strings.Trim(s, " ") + "
  • " } return template.HTML("
      " + v + "
    ") diff --git a/main.go b/main.go index cd23aea..34086cc 100644 --- a/main.go +++ b/main.go @@ -79,6 +79,7 @@ func main() { Handle() for _, cp := range customPages { + slog.Info("Creating custom page...", "title", cp.Title, "uri", cp.URI) g.NewTemplate("custom_page", cp.URI, cp.Title, diff --git a/schema.json b/schema.json index dcc75ef..9b325c3 100644 --- a/schema.json +++ b/schema.json @@ -177,7 +177,7 @@ "tags" ] }, - "custom_page": { + "custom_pages": { "type": "array" } },