aboutsummaryrefslogtreecommitdiff
path: root/data.go
blob: b97244623de720713e87fb06b99720394e5108f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main

import (
	"html/template"
	"log/slog"
	"strconv"
)

type Data struct {
	Image           string           `json:"image"`
	Description     string           `json:"description"`
	Person          *Person          `json:"person"`
	BackgroundColor *BackgroundColor `json:"background_color"`
}

type Person struct {
	Name     string `json:"name"`
	Pronouns string `json:"pronouns"`
	Image    string `json:"image"`
}

type BackgroundColor struct {
	Type   string `json:"type"`
	Angle  uint   `json:"angle"`
	Colors []struct {
		Color    string `json:"color"`
		Position uint   `json:"position"`
	} `json:"colors"`
}

func (d *Data) GetBackground() template.CSS {
	bg := d.BackgroundColor
	css := "background: " + bg.Type + "-gradient("
	slog.Info(css)
	if bg.Type == "linear" {
		css += strconv.Itoa(int(bg.Angle)) + "deg,"
	}
	slog.Info(css)
	for _, c := range bg.Colors {
		css += c.Color + " " + strconv.Itoa(int(c.Position)) + "%,"
		slog.Info(css)
	}
	slog.Info(css[:len(css)-1] + ");")
	return template.CSS(css[:len(css)-1] + ");")
}