style(data): rename data with config
This commit is contained in:
parent
3b7bc746af
commit
b0a86973a3
4 changed files with 25 additions and 25 deletions
|
@ -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
14
data.go
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
30
main.go
30
main.go
|
@ -13,13 +13,13 @@ import (
|
|||
var templates embed.FS
|
||||
|
||||
var (
|
||||
domain string
|
||||
dataPath string
|
||||
domain 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",
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue