style(data): rename data with config

This commit is contained in:
Anhgelus Morhtuuzh 2024-11-10 01:41:27 +01:00
parent 3b7bc746af
commit b0a86973a3
No known key found for this signature in database
GPG key ID: CAD341EFA92DDDE5
4 changed files with 25 additions and 25 deletions

View file

@ -17,8 +17,8 @@ COPY --from=builder . .
RUN go mod tidy && go mod build -o app . RUN go mod tidy && go mod build -o app .
ENV NOW_DOMAIN="" ENV NOW_DOMAIN=""
ENV NOW_DATA="" ENV NOW_CONFIG=""
EXPOSE 80 EXPOSE 80
CMD ./app -domain $NOW_DOMAIN -data $NOW_DATA CMD ./app -domain $NOW_DOMAIN -config $NOW_CONFIG

14
data.go
View file

@ -6,7 +6,7 @@ import (
"strconv" "strconv"
) )
type Data struct { type Config 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"`
@ -49,8 +49,8 @@ type Legal struct {
ImagesSource []string `json:"images_source"` ImagesSource []string `json:"images_source"`
} }
func (d *Data) GetBackground() template.CSS { func (c *Config) GetBackground() template.CSS {
bg := d.Color.Background bg := c.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,"
@ -61,12 +61,12 @@ func (d *Data) GetBackground() template.CSS {
return template.CSS(css[:len(css)-1] + ");") return template.CSS(css[:len(css)-1] + ");")
} }
func (d *Data) GetBackgroundImage() template.CSS { func (c *Config) GetBackgroundImage() template.CSS {
return template.CSS("--background-image: url(" + golatt.GetStaticPath(d.Image) + ");") return template.CSS("--background-image: url(" + golatt.GetStaticPath(c.Image) + ");")
} }
func (d *Data) GetTextColor() template.CSS { func (c *Config) GetTextColor() template.CSS {
return template.CSS("--text-color: " + d.Color.Text + ";") return template.CSS("--text-color: " + c.Color.Text + ";")
} }
func (l *Link) GetLinkColor() template.CSS { func (l *Link) GetLinkColor() template.CSS {

View file

@ -3,7 +3,7 @@ services:
build: . build: .
environment: environment:
NOW_DOMAIN: "example.org" NOW_DOMAIN: "example.org"
NOW_DATA: "data.json" NOW_CONFIG: "config.json"
volumes: volumes:
- ./data.json:/app/data.json:ro - ./data.json:/app/data.json:ro
- ./assets:/app/public:ro - ./assets:/app/public:ro

28
main.go
View file

@ -14,12 +14,12 @@ var templates embed.FS
var ( var (
domain string domain string
dataPath string configPath string
) )
func init() { func init() {
flag.StringVar(&domain, "domain", "", "domain to use") flag.StringVar(&domain, "domain", "", "domain to use")
flag.StringVar(&dataPath, "data", "", "data to use") flag.StringVar(&configPath, "config", "", "config to use")
} }
func main() { func main() {
@ -31,26 +31,26 @@ func main() {
return return
} }
} }
if dataPath == "" { if configPath == "" {
dataPath = os.Getenv("NOW_DATA") configPath = os.Getenv("NOW_DATA")
if dataPath == "" { if configPath == "" {
slog.Error("Data not set. Set it with --data relative path or with the env NOW_DATA") slog.Error("Config not set. Set it with --cfg relative path or with the env NOW_DATA")
return return
} }
} }
b, err := os.ReadFile(dataPath) b, err := os.ReadFile(configPath)
if err != nil { if err != nil {
panic(err) panic(err)
} }
var data Data var cfg Config
err = json.Unmarshal(b, &data) err = json.Unmarshal(b, &cfg)
if err != nil { if err != nil {
panic(err) panic(err)
} }
g := golatt.New(templates) g := golatt.New(templates)
g.DefaultSeoData = &golatt.SeoData{ g.DefaultSeoData = &golatt.SeoData{
Image: data.Image, Image: cfg.Image,
Description: data.Description, Description: cfg.Description,
Domain: domain, Domain: domain,
} }
g.Templates = append(g.Templates, "templates/base/*.gohtml") g.Templates = append(g.Templates, "templates/base/*.gohtml")
@ -58,15 +58,15 @@ func main() {
home := golatt.Template{ home := golatt.Template{
Golatt: g, Golatt: g,
Name: "index", Name: "index",
Title: data.Person.Name, Title: cfg.Person.Name,
Data: &data, Data: &cfg,
URL: "/", URL: "/",
} }
credits := golatt.Template{ credits := golatt.Template{
Golatt: g, Golatt: g,
Name: "credits", Name: "credits",
Title: "Credits", Title: "Credits",
Data: &data, Data: &cfg,
URL: "/credits", URL: "/credits",
} }