feat(config): support every path
This commit is contained in:
parent
7b5d816992
commit
91f2ef06c0
3 changed files with 29 additions and 11 deletions
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -175,7 +175,4 @@ dist
|
|||
|
||||
# Test files
|
||||
public/
|
||||
config.json
|
||||
legal.html
|
||||
test.html
|
||||
test.json
|
||||
test
|
||||
|
|
23
data.go
23
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
|
||||
}
|
||||
|
|
12
main.go
12
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),
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue