feat(style): custom colors

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

22
data.go
View file

@ -9,7 +9,7 @@ type Data struct {
Image string `json:"image"` Image string `json:"image"`
Description string `json:"description"` Description string `json:"description"`
Person *Person `json:"person"` Person *Person `json:"person"`
BackgroundColor *BackgroundColor `json:"background_color"` Color *Color `json:"colors"`
Links []*Link `json:"links"` Links []*Link `json:"links"`
} }
@ -19,6 +19,11 @@ type Person struct {
Image string `json:"image"` Image string `json:"image"`
} }
type Color struct {
Background *BackgroundColor `json:"background"`
Text string `json:"text"`
}
type BackgroundColor struct { type BackgroundColor struct {
Type string `json:"type"` Type string `json:"type"`
Angle uint `json:"angle"` Angle uint `json:"angle"`
@ -32,10 +37,11 @@ type Link struct {
Link string `json:"link"` Link string `json:"link"`
Content string `json:"content"` Content string `json:"content"`
Color string `json:"color"` Color string `json:"color"`
TextColor string `json:"text_color"`
} }
func (d *Data) GetBackground() template.CSS { func (d *Data) GetBackground() template.CSS {
bg := d.BackgroundColor bg := d.Color.Background
css := "background: " + bg.Type + "-gradient(" css := "background: " + bg.Type + "-gradient("
if bg.Type == "linear" { if bg.Type == "linear" {
css += strconv.Itoa(int(bg.Angle)) + "deg," css += strconv.Itoa(int(bg.Angle)) + "deg,"
@ -46,6 +52,14 @@ func (d *Data) GetBackground() template.CSS {
return template.CSS(css[:len(css)-1] + ");") return template.CSS(css[:len(css)-1] + ");")
} }
func (l *Link) GetBackground() template.CSS { func (d *Data) GetTextColor() template.CSS {
return template.CSS("background: " + l.Color) return template.CSS("color: " + d.Color.Text + ";")
}
func (l *Link) GetLinkColor() template.CSS {
return template.CSS("color: " + l.TextColor + ";")
}
func (l *Link) GetBackground() template.CSS {
return template.CSS("background: " + l.Color + ";")
} }

View file

@ -6,7 +6,9 @@
"pronouns": "he/his - some basic things though", "pronouns": "he/his - some basic things though",
"image": "pfp.webp" "image": "pfp.webp"
}, },
"background_color": { "colors": {
"text": "#fff",
"background": {
"type": "linear", "type": "linear",
"angle": 243, "angle": 243,
"colors": [ "colors": [
@ -23,22 +25,26 @@
"position": 100 "position": 100
} }
] ]
}
}, },
"links": [ "links": [
{ {
"link": "https://discord.gg/minecraft", "link": "https://discord.gg/minecraft",
"content": "Minecraft's Discord", "content": "Minecraft's Discord",
"color": "#800080FF" "color": "#800080FF",
"text_color": "#fff"
}, },
{ {
"link": "https://github.com/anhgelus", "link": "https://github.com/anhgelus",
"content": "GitHub", "content": "GitHub",
"color": "#800080FF" "color": "#800080FF",
"text_color": "#fff"
}, },
{ {
"link": "https://youtube.com/@anhgelus", "link": "https://youtube.com/@anhgelus",
"content": "YouTube", "content": "YouTube",
"color": "#800080FF" "color": "#800080FF",
"text_color": "#fff"
} }
] ]
} }

View file

@ -21,7 +21,6 @@ body {
main { main {
width: 50%; width: 50%;
background: mediumpurple;
padding: 2rem; padding: 2rem;
border-radius: 32px; border-radius: 32px;
box-shadow: 0 0 70px 2px rgba(0,0,0,0.75); box-shadow: 0 0 70px 2px rgba(0,0,0,0.75);
@ -73,7 +72,6 @@ h2 {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
background: purple;
width: 33%; width: 33%;
border-radius: 16px; border-radius: 16px;
} }

View file

@ -1,5 +1,5 @@
{{define "body"}} {{define "body"}}
<main style="{{ .GetBackground }}"> <main style="{{ .GetBackground }}{{ .GetTextColor }}">
<div class="presentation"> <div class="presentation">
<figure> <figure>
<img src="{{ getStaticPath .Person.Image }}" alt="{{ .Person.Name }}'s image"> <img src="{{ getStaticPath .Person.Image }}" alt="{{ .Person.Name }}'s image">
@ -12,7 +12,9 @@
<p class="description">{{ .Description }}</p> <p class="description">{{ .Description }}</p>
<div class="links"> <div class="links">
{{ range $link := .Links }} {{ range $link := .Links }}
<div class="link" style="{{ $link.GetBackground }}"><a href="{{ $link.Link }}">{{ $link.Content }}</a></div> <div class="link" style="{{ .GetBackground }}">
<a href="{{ .Link }}" style="{{ .GetLinkColor }}">{{ .Content }}</a>
</div>
{{end}} {{end}}
</div> </div>
</main> </main>