diff options
| author | William Hergès <william@herges.fr> | 2025-08-01 12:54:51 +0200 |
|---|---|---|
| committer | William Hergès <william@herges.fr> | 2025-08-01 12:54:51 +0200 |
| commit | b87964e81f99e03dd5ed2983d3788ae2170de237 (patch) | |
| tree | 87f67980eda97dc8e228588ad0d33004156649f1 /data.go | |
| parent | b7829c52685fe019e9de66f562206f909bd67876 (diff) | |
feat(config): supports external link for images
Diffstat (limited to 'data.go')
| -rw-r--r-- | data.go | 16 |
1 files changed, 14 insertions, 2 deletions
@@ -7,10 +7,15 @@ import ( "github.com/anhgelus/golatt" "html/template" "os" + "regexp" "strconv" "strings" ) +var ( + regexExternalLink = regexp.MustCompile(`https?://`) +) + type ConfigData interface { GetTextColor() template.CSS GetBackground() template.CSS @@ -70,12 +75,19 @@ type Link struct { Content string `json:"content" toml:"content"` } +func getImage(s string) string { + if regexExternalLink.MatchString(s) { + return s + } + return golatt.GetStaticPath(s) +} + func (c *Config) GetBackground() template.CSS { return c.Color.GetBackground() } func (c *Config) GetBackgroundImage() template.CSS { - return template.CSS("--background-image: url(" + golatt.GetStaticPath(c.Image) + ");") + return template.CSS("--background-image: url(" + getImage(c.Image) + ");") } func (c *Config) GetTextColor() template.CSS { @@ -168,7 +180,7 @@ func (p *CustomPage) GetTextColor() template.CSS { } func (p *CustomPage) GetBackgroundImage() template.CSS { - return template.CSS("--background-image: url(" + golatt.GetStaticPath(p.Image) + ");") + return template.CSS("--background-image: url(" + getImage(p.Image) + ");") } func (p *CustomPage) GetBackground() template.CSS { |
