aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <anhgelus@anhgelus.world>2025-03-10 10:56:47 +0100
committerAnhgelus Morhtuuzh <anhgelus@anhgelus.world>2025-03-10 10:56:47 +0100
commit2d74d8afc321cf84fd5710314bfa6a9ff3c10a32 (patch)
treeca366fc817e80a96526932131de3bc810d287cc3
parentf98647cabbd3af21acbb801fcbd65548690bd4c7 (diff)
refactor(pages): use html instead of json to render legal
-rw-r--r--config.schema.json23
-rw-r--r--data.go21
-rw-r--r--main.go9
-rw-r--r--templates/page/legal.gohtml10
4 files changed, 18 insertions, 45 deletions
diff --git a/config.schema.json b/config.schema.json
index 9b325c3..2e8a7c1 100644
--- a/config.schema.json
+++ b/config.schema.json
@@ -92,27 +92,8 @@
"type": "string"
},
"legal": {
- "type": "object",
- "properties": {
- "font_source": {
- "type": "string"
- },
- "images_source": {
- "type": "array",
- "items": {
- "type": "string"
- }
- },
- "legal_information_link": {
- "type": "string"
- }
- },
- "additionalProperties": false,
- "required": [
- "legal_information_link",
- "images_source",
- "font_source"
- ]
+ "type": "string",
+ "additionalProperties": false
},
"links": {
"type": "array",
diff --git a/data.go b/data.go
index 140f914..8c134b1 100644
--- a/data.go
+++ b/data.go
@@ -34,7 +34,7 @@ type Config struct {
Person *Person `json:"person" toml:"person"`
Color *Color `json:"colors" toml:"colors"`
Links []*Link `json:"links" toml:"links"`
- Legal *Legal `json:"legal" toml:"legal"`
+ Legal string `json:"legal" toml:"legal"`
CustomPages []string `json:"custom_pages" toml:"custom_pages"`
}
@@ -79,12 +79,6 @@ type Link struct {
Content string `json:"content" toml:"content"`
}
-type Legal struct {
- LegalInformationLink string `json:"legal_information_link" toml:"legal_information_link"`
- ImagesSource []string `json:"images_source" toml:"images_source"`
- FontSource string `json:"font_source" toml:"font_source"`
-}
-
func (c *Config) GetBackground() template.CSS {
return c.Color.GetBackground()
}
@@ -142,6 +136,19 @@ func (c *Config) LoadCustomPages() ([]*CustomPage, error) {
return pages, nil
}
+var legalContent template.HTML
+
+func (c *Config) GetLegal() (template.HTML, error) {
+ if legalContent == "" {
+ b, err := os.ReadFile(c.Legal)
+ if err != nil {
+ return "", err
+ }
+ legalContent = template.HTML(b)
+ }
+ return legalContent, nil
+}
+
func (t *Color) GetTextColor() template.CSS {
return template.CSS("--text-color: " + t.Text + ";")
}
diff --git a/main.go b/main.go
index 0bc9dc9..bf5905e 100644
--- a/main.go
+++ b/main.go
@@ -172,14 +172,7 @@ func generateConfigFile(isToml bool) {
{"/foo", "Blog"},
{"https://www.youtube.com/@anhgelus", "YouTube"},
},
- Legal: &Legal{
- LegalInformationLink: "/bar",
- ImagesSource: []string{
- "Profile picture: some one on website",
- "Background picture: another one on another website",
- },
- FontSource: "Name by some one on website",
- },
+ Legal: "legal.html",
CustomPages: []string{"custom.json"},
}
var b []byte
diff --git a/templates/page/legal.gohtml b/templates/page/legal.gohtml
index 0e37f49..8b617ab 100644
--- a/templates/page/legal.gohtml
+++ b/templates/page/legal.gohtml
@@ -2,18 +2,10 @@
<div class="credits-legal" style="{{ .GetBackground }}">
<h2>Legal information</h2>
<p>
- Other legal information are available <a href="{{ .Legal.LegalInformationLink }}" target="_blank">here</a>.
- </p>
- <p>
The software behind this website was made by <a href="https://www.anhgelus.world/" target="_blank">Anhgelus Morhtuuzh</a>.
It is available on <a href="https://github.com/anhgelus/now">GitHub</a> for free and licensed under the
<a href="https://github.com/anhgelus/now/blob/main/LICENSE" target="_blank">AGPL</a> license.
</p>
- <h3>Image credits</h3>
- {{ range $s := .Legal.ImagesSource }}
- <p>{{ . }}</p>
- {{ end }}
- <h3>Font credits</h3>
- <p>{{ .Legal.FontSource }}</p>
+ {{ .GetLegal }}
</div>
{{end}}