feat(link): custom links

This commit is contained in:
Anhgelus Morhtuuzh 2024-11-09 23:37:10 +01:00
parent 0b90249205
commit 5b98185aa6
No known key found for this signature in database
GPG key ID: CAD341EFA92DDDE5
4 changed files with 37 additions and 11 deletions

16
data.go
View file

@ -2,7 +2,6 @@ package main
import ( import (
"html/template" "html/template"
"log/slog"
"strconv" "strconv"
) )
@ -11,6 +10,7 @@ type Data struct {
Description string `json:"description"` Description string `json:"description"`
Person *Person `json:"person"` Person *Person `json:"person"`
BackgroundColor *BackgroundColor `json:"background_color"` BackgroundColor *BackgroundColor `json:"background_color"`
Links []*Link `json:"links"`
} }
type Person struct { type Person struct {
@ -28,18 +28,24 @@ type BackgroundColor struct {
} `json:"colors"` } `json:"colors"`
} }
type Link struct {
Link string `json:"link"`
Content string `json:"content"`
Color string `json:"color"`
}
func (d *Data) GetBackground() template.CSS { func (d *Data) GetBackground() template.CSS {
bg := d.BackgroundColor bg := d.BackgroundColor
css := "background: " + bg.Type + "-gradient(" css := "background: " + bg.Type + "-gradient("
slog.Info(css)
if bg.Type == "linear" { if bg.Type == "linear" {
css += strconv.Itoa(int(bg.Angle)) + "deg," css += strconv.Itoa(int(bg.Angle)) + "deg,"
} }
slog.Info(css)
for _, c := range bg.Colors { for _, c := range bg.Colors {
css += c.Color + " " + strconv.Itoa(int(c.Position)) + "%," css += c.Color + " " + strconv.Itoa(int(c.Position)) + "%,"
slog.Info(css)
} }
slog.Info(css[:len(css)-1] + ");")
return template.CSS(css[:len(css)-1] + ");") return template.CSS(css[:len(css)-1] + ");")
} }
func (l *Link) GetBackground() template.CSS {
return template.CSS("background: " + l.Color)
}

View file

@ -23,5 +23,22 @@
"position": 100 "position": 100
} }
] ]
},
"links": [
{
"link": "https://discord.gg/minecraft",
"content": "Minecraft's Discord",
"color": "#800080FF"
},
{
"link": "https://github.com/anhgelus",
"content": "GitHub",
"color": "#800080FF"
},
{
"link": "https://youtube.com/@anhgelus",
"content": "YouTube",
"color": "#800080FF"
} }
]
} }

View file

@ -70,10 +70,11 @@ h2 {
width: 100%; width: 100%;
gap: 1rem; gap: 1rem;
& .link { & .link {
display: block; display: flex;
align-items: center;
justify-content: center;
background: purple; background: purple;
width: 33%; width: 33%;
padding: 1em;
border-radius: 16px; border-radius: 16px;
} }
& a { & a {
@ -81,5 +82,7 @@ h2 {
color: black; color: black;
text-decoration: none; text-decoration: none;
text-align: center; text-align: center;
padding: 1em;
width: 100%;
} }
} }

View file

@ -11,9 +11,9 @@
</div> </div>
<p class="description">{{ .Description }}</p> <p class="description">{{ .Description }}</p>
<div class="links"> <div class="links">
<div class="link"><a href="">Link 1</a></div> {{ range $link := .Links }}
<div class="link"><a href="">Link 2</a></div> <div class="link" style="{{ $link.GetBackground }}"><a href="{{ $link.Link }}">{{ $link.Content }}</a></div>
<div class="link"><a href="">Link 3</a></div> {{end}}
</div> </div>
</main> </main>
{{end}} {{end}}