fix(custom): missing method for new config

This commit is contained in:
Anhgelus Morhtuuzh 2024-12-10 19:13:44 +01:00
parent 279f73187b
commit e379601ec1
No known key found for this signature in database
GPG key ID: CAD341EFA92DDDE5
3 changed files with 43 additions and 13 deletions

53
data.go
View file

@ -18,6 +18,12 @@ const (
OrderedListContentType = "ordered_list" OrderedListContentType = "ordered_list"
) )
type ConfigData interface {
GetTextColor() template.CSS
GetBackground() template.CSS
GetBackgroundImage() template.CSS
}
type Config struct { type Config struct {
Image string `json:"image"` Image string `json:"image"`
Description string `json:"description"` Description string `json:"description"`
@ -76,15 +82,7 @@ type Legal struct {
} }
func (c *Config) GetBackground() template.CSS { func (c *Config) GetBackground() template.CSS {
bg := c.Color.Background return c.Color.GetBackground()
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 (c *Config) GetBackgroundImage() template.CSS { func (c *Config) GetBackgroundImage() template.CSS {
@ -115,6 +113,7 @@ type Content interface {
func (c *Config) LoadCustomPages() ([]*CustomPage, error) { func (c *Config) LoadCustomPages() ([]*CustomPage, error) {
if c.CustomPages == nil { if c.CustomPages == nil {
println("null")
return nil, nil return nil, nil
} }
var pages []*CustomPage var pages []*CustomPage
@ -123,12 +122,12 @@ func (c *Config) LoadCustomPages() ([]*CustomPage, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var p *CustomPage var p CustomPage
err = json.Unmarshal(b, p) err = json.Unmarshal(b, &p)
if err != nil { if err != nil {
return nil, err return nil, err
} }
pages = append(pages, p) pages = append(pages, &p)
} }
return pages, nil return pages, nil
} }
@ -137,6 +136,18 @@ func (t *Color) GetTextColor() template.CSS {
return template.CSS("--text-color: " + t.Text + ";") 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 { func (b *ButtonColor) GetTextColor() template.CSS {
return template.CSS("--text-color: " + b.Text + ";--text-color-hover: " + b.TextHover + ";") 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 + ";") 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 { func (c *CustomContent) Get() template.HTML {
if c.Type == TitleContentType { if c.Type == TitleContentType {
return template.HTML("<h2>" + c.Content + "</h2>") return template.HTML("<h2>" + c.Content + "</h2>")
@ -159,12 +182,18 @@ func (c *CustomContent) Get() template.HTML {
} else if c.Type == ListContentType { } else if c.Type == ListContentType {
v := "" v := ""
for _, s := range strings.Split(c.Content, "--") { for _, s := range strings.Split(c.Content, "--") {
if len(strings.Trim(s, " ")) == 0 {
continue
}
v += "<li>" + strings.Trim(s, " ") + "</li>" v += "<li>" + strings.Trim(s, " ") + "</li>"
} }
return template.HTML("<ul>" + v + "</ul>") return template.HTML("<ul>" + v + "</ul>")
} else if c.Type == OrderedListContentType { } else if c.Type == OrderedListContentType {
v := "" v := ""
for _, s := range strings.Split(c.Content, "--") { for _, s := range strings.Split(c.Content, "--") {
if len(strings.Trim(s, " ")) == 0 {
continue
}
v += "<li>" + strings.Trim(s, " ") + "</li>" v += "<li>" + strings.Trim(s, " ") + "</li>"
} }
return template.HTML("<ol>" + v + "</ol>") return template.HTML("<ol>" + v + "</ol>")

View file

@ -79,6 +79,7 @@ func main() {
Handle() Handle()
for _, cp := range customPages { for _, cp := range customPages {
slog.Info("Creating custom page...", "title", cp.Title, "uri", cp.URI)
g.NewTemplate("custom_page", g.NewTemplate("custom_page",
cp.URI, cp.URI,
cp.Title, cp.Title,

View file

@ -177,7 +177,7 @@
"tags" "tags"
] ]
}, },
"custom_page": { "custom_pages": {
"type": "array" "type": "array"
} }
}, },