aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data.go16
-rw-r--r--main.go5
-rw-r--r--templates/page/index.gohtml2
3 files changed, 20 insertions, 3 deletions
diff --git a/data.go b/data.go
index 75ec2d0..f95289a 100644
--- a/data.go
+++ b/data.go
@@ -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 {
diff --git a/main.go b/main.go
index 4ef6f6d..23c3f69 100644
--- a/main.go
+++ b/main.go
@@ -7,6 +7,7 @@ import (
"fmt"
"github.com/BurntSushi/toml"
"github.com/anhgelus/golatt"
+ "html/template"
"log/slog"
"net/http"
"os"
@@ -127,6 +128,10 @@ func main() {
http.Redirect(w, r, "/", http.StatusTemporaryRedirect)
}
+ g.TemplateFuncMap = template.FuncMap{
+ "getImage": getImage,
+ }
+
host := fmt.Sprintf(":%d", port)
if dev {
if port != 80 {
diff --git a/templates/page/index.gohtml b/templates/page/index.gohtml
index f0ebaea..21d4423 100644
--- a/templates/page/index.gohtml
+++ b/templates/page/index.gohtml
@@ -2,7 +2,7 @@
<main style="{{ .GetBackground }}">
<div class="presentation">
<figure>
- <img src="{{ getStaticPath .Person.Image }}" alt="{{ .Person.Name }}'s image">
+ <img src="{{ getImage .Person.Image }}" alt="{{ .Person.Name }}'s image">
</figure>
<div class="presentation__information">
<h2>{{ .Person.Name }}</h2>