From 3b37150f6ee5d4aa40028f249891bbed73c96f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20Herg=C3=A8s?= Date: Fri, 15 Aug 2025 21:30:44 +0200 Subject: refactor(config): scope folder per config file --- main.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 35f8e78..f8f82aa 100644 --- a/main.go +++ b/main.go @@ -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", -- cgit v1.2.3