diff --git a/.gitignore b/.gitignore index 7e17006..ee6393f 100644 --- a/.gitignore +++ b/.gitignore @@ -175,7 +175,4 @@ dist # Test files public/ -config.json -legal.html -test.html -test.json +test diff --git a/data.go b/data.go index f95289a..94cd08d 100644 --- a/data.go +++ b/data.go @@ -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 } diff --git a/main.go b/main.go index 23c3f69..35f8e78 100644 --- a/main.go +++ b/main.go @@ -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), ) }