aboutsummaryrefslogtreecommitdiff
path: root/data.go
blob: d085b99c3cc17f6eb68aefe5ccbfa2f92252f1b7 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main

import (
	"github.com/anhgelus/golatt"
	"html/template"
	"strconv"
)

type Data struct {
	Image       string  `json:"image"`
	Description string  `json:"description"`
	Person      *Person `json:"person"`
	Color       *Color  `json:"colors"`
	Links       []*Link `json:"links"`
	Legal       *Legal  `json:"legal"`
}

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

type Color struct {
	Background *BackgroundColor `json:"background"`
	Text       string           `json:"text"`
}

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

type Link struct {
	Link           string `json:"link"`
	Content        string `json:"content"`
	Color          string `json:"color"`
	TextColor      string `json:"text_color"`
	ColorHover     string `json:"color_hover"`
	TextColorHover string `json:"text_color_hover"`
}

type Legal struct {
	LegalInformationLink string   `json:"legal_information_link"`
	ImagesSource         []string `json:"images_source"`
}

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

func (d *Data) GetBackgroundImage() template.CSS {
	return template.CSS("--background-image: url(" + golatt.GetStaticPath(d.Image) + ");")
}

func (d *Data) GetTextColor() template.CSS {
	return template.CSS("--text-color: " + d.Color.Text + ";")
}

func (l *Link) GetLinkColor() template.CSS {
	return template.CSS("--text-color: " + l.TextColor + ";--text-color-hover: " + l.TextColorHover + ";")
}

func (l *Link) GetBackground() template.CSS {
	return template.CSS("--background: " + l.Color + ";--background-hover: " + l.ColorHover + ";")
}