diff options
| author | William Hergès <william@herges.fr> | 2025-08-15 21:12:11 +0200 |
|---|---|---|
| committer | William Hergès <william@herges.fr> | 2025-08-15 21:12:11 +0200 |
| commit | 91f2ef06c09b7dce9c5a9708f6d9d40ee157a90f (patch) | |
| tree | 3151d755b2c4931125d597a3a348f86e5404451c | |
| parent | 7b5d816992fe26594fbfbedfd46baef708b9d1ca (diff) | |
feat(config): support every path
| -rw-r--r-- | .gitignore | 5 | ||||
| -rw-r--r-- | data.go | 23 | ||||
| -rw-r--r-- | main.go | 12 |
3 files changed, 29 insertions, 11 deletions
@@ -175,7 +175,4 @@ dist # Test files public/ -config.json -legal.html -test.html -test.json +test @@ -82,6 +82,23 @@ func getImage(s string) string { return golatt.GetStaticPath(s) } +func getPath(filename string) string { + if !strings.Contains(configPath, "/") { + return filename + } + sp := strings.Split(configPath, "/") + before := strings.Join(sp[1:len(sp)-1], "/") + if configPath[0] != '/' && !strings.HasPrefix(configPath, "./") { + if len(before) == 0 { + before = sp[0] + } else { + before = sp[0] + "/" + before + } + } + before += "/" + return before + filename +} + func (c *Config) GetBackground() template.CSS { return c.Color.GetBackground() } @@ -102,7 +119,7 @@ var legalContent template.HTML func (c *Config) GetLegal() (template.HTML, error) { if legalContent == "" { - b, err := os.ReadFile(c.Legal) + b, err := os.ReadFile(getPath(c.Legal)) if err != nil { return "", err } @@ -127,7 +144,7 @@ func (c *Config) LoadCustomPages() ([]*CustomPage, error) { } var pages []*CustomPage for _, cp := range c.CustomPages { - b, err := os.ReadFile(cp) + b, err := os.ReadFile(getPath(cp)) if err != nil { return nil, err } @@ -196,7 +213,7 @@ var contentsMap = map[string]template.HTML{} func (p *CustomPage) GetContent() (template.HTML, error) { res, ok := contentsMap[p.URI] if !ok { - b, err := os.ReadFile(p.Content) + b, err := os.ReadFile(getPath(p.Content)) if err != nil { return "", err } @@ -24,10 +24,10 @@ var ( var ( domain string configPath string - dev bool = false + dev = false generateToml bool generateJson bool - port int = 80 + port = 80 ) func init() { @@ -82,11 +82,15 @@ func main() { var g *golatt.Golatt if dev { - g = golatt.New(golatt.UsableEmbedFS("templates", templates), os.DirFS("public"), os.DirFS("dist")) + g = golatt.New( + golatt.UsableEmbedFS("templates", templates), + os.DirFS(getPath("public")), + os.DirFS("dist"), + ) } else { g = golatt.New( golatt.UsableEmbedFS("templates", templates), - os.DirFS("public"), + os.DirFS(getPath("public")), golatt.UsableEmbedFS("dist", assets), ) } |
