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 .
ENV NOW_DOMAIN=""
ENV NOW_DATA=""
ENV NOW_CONFIG=""
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"
)
type Data struct {
type Config struct {
Image string `json:"image"`
Description string `json:"description"`
Person *Person `json:"person"`
@ -49,8 +49,8 @@ type Legal struct {
ImagesSource []string `json:"images_source"`
}
func (d *Data) GetBackground() template.CSS {
bg := d.Color.Background
func (c *Config) GetBackground() template.CSS {
bg := c.Color.Background
css := "background: " + bg.Type + "-gradient("
if bg.Type == "linear" {
css += strconv.Itoa(int(bg.Angle)) + "deg,"
@ -61,12 +61,12 @@ func (d *Data) GetBackground() template.CSS {
return template.CSS(css[:len(css)-1] + ");")
}
func (d *Data) GetBackgroundImage() template.CSS {
return template.CSS("--background-image: url(" + golatt.GetStaticPath(d.Image) + ");")
func (c *Config) GetBackgroundImage() template.CSS {
return template.CSS("--background-image: url(" + golatt.GetStaticPath(c.Image) + ");")
}
func (d *Data) GetTextColor() template.CSS {
return template.CSS("--text-color: " + d.Color.Text + ";")
func (c *Config) GetTextColor() template.CSS {
return template.CSS("--text-color: " + c.Color.Text + ";")
}
func (l *Link) GetLinkColor() template.CSS {

View file

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

28
main.go
View file

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