refactor(pages): use html instead of json to render legal

This commit is contained in:
Anhgelus Morhtuuzh 2025-03-10 10:56:47 +01:00
parent f98647cabb
commit 2d74d8afc3
No known key found for this signature in database
GPG key ID: CAD341EFA92DDDE5
4 changed files with 18 additions and 45 deletions

View file

@ -92,27 +92,8 @@
"type": "string" "type": "string"
}, },
"legal": { "legal": {
"type": "object", "type": "string",
"properties": { "additionalProperties": false
"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"
]
}, },
"links": { "links": {
"type": "array", "type": "array",

21
data.go
View file

@ -34,7 +34,7 @@ type Config struct {
Person *Person `json:"person" toml:"person"` Person *Person `json:"person" toml:"person"`
Color *Color `json:"colors" toml:"colors"` Color *Color `json:"colors" toml:"colors"`
Links []*Link `json:"links" toml:"links"` 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"` CustomPages []string `json:"custom_pages" toml:"custom_pages"`
} }
@ -79,12 +79,6 @@ type Link struct {
Content string `json:"content" toml:"content"` 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 { func (c *Config) GetBackground() template.CSS {
return c.Color.GetBackground() return c.Color.GetBackground()
} }
@ -142,6 +136,19 @@ func (c *Config) LoadCustomPages() ([]*CustomPage, error) {
return pages, nil 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 { func (t *Color) GetTextColor() template.CSS {
return template.CSS("--text-color: " + t.Text + ";") return template.CSS("--text-color: " + t.Text + ";")
} }

View file

@ -172,14 +172,7 @@ func generateConfigFile(isToml bool) {
{"/foo", "Blog"}, {"/foo", "Blog"},
{"https://www.youtube.com/@anhgelus", "YouTube"}, {"https://www.youtube.com/@anhgelus", "YouTube"},
}, },
Legal: &Legal{ Legal: "legal.html",
LegalInformationLink: "/bar",
ImagesSource: []string{
"Profile picture: some one on website",
"Background picture: another one on another website",
},
FontSource: "Name by some one on website",
},
CustomPages: []string{"custom.json"}, CustomPages: []string{"custom.json"},
} }
var b []byte var b []byte

View file

@ -1,19 +1,11 @@
{{define "body"}} {{define "body"}}
<div class="credits-legal" style="{{ .GetBackground }}"> <div class="credits-legal" style="{{ .GetBackground }}">
<h2>Legal information</h2> <h2>Legal information</h2>
<p>
Other legal information are available <a href="{{ .Legal.LegalInformationLink }}" target="_blank">here</a>.
</p>
<p> <p>
The software behind this website was made by <a href="https://www.anhgelus.world/" target="_blank">Anhgelus Morhtuuzh</a>. 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 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. <a href="https://github.com/anhgelus/now/blob/main/LICENSE" target="_blank">AGPL</a> license.
</p> </p>
<h3>Image credits</h3> {{ .GetLegal }}
{{ range $s := .Legal.ImagesSource }}
<p>{{ . }}</p>
{{ end }}
<h3>Font credits</h3>
<p>{{ .Legal.FontSource }}</p>
</div> </div>
{{end}} {{end}}