refactor(config): scope folder per config file
This commit is contained in:
parent
91f2ef06c0
commit
3b37150f6e
2 changed files with 29 additions and 22 deletions
23
main.go
23
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",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue