refactor(config): scope folder per config file

This commit is contained in:
Anhgelus Morhtuuzh 2025-08-15 21:30:44 +02:00
parent 91f2ef06c0
commit 3b37150f6e
Signed by: anhgelus
GPG key ID: 617773CACE89052C
2 changed files with 29 additions and 22 deletions

23
main.go
View file

@ -75,6 +75,9 @@ func main() {
if err != nil {
panic(err)
}
cfg.folder = getFolder(configPath)
customPages, err := cfg.LoadCustomPages()
if err != nil {
panic(err)
@ -84,13 +87,13 @@ func main() {
if dev {
g = golatt.New(
golatt.UsableEmbedFS("templates", templates),
os.DirFS(getPath("public")),
os.DirFS(cfg.folder+"public"),
os.DirFS("dist"),
)
} else {
g = golatt.New(
golatt.UsableEmbedFS("templates", templates),
os.DirFS(getPath("public")),
os.DirFS(cfg.folder+"public"),
golatt.UsableEmbedFS("dist", assets),
)
}
@ -148,6 +151,22 @@ func main() {
}
}
func getFolder(path string) string {
if !strings.Contains(path, "/") {
return ""
}
sp := strings.Split(path, "/")
folder := strings.Join(sp[1:len(sp)-1], "/")
if path[0] != '/' && !strings.HasPrefix(path, "./") {
if len(folder) == 0 {
folder = sp[0]
} else {
folder = sp[0] + "/" + folder
}
}
return folder + "/"
}
func generateConfigFile(isToml bool) {
cfg := Config{
Image: "wallpaper.webp",