Add trailing slash to page paths

This commit is contained in:
adnano 2020-11-25 14:31:58 -05:00
parent 9676566325
commit 71f415e54d
2 changed files with 3 additions and 13 deletions

14
main.go
View file

@ -58,24 +58,14 @@ type outputFormat func(*Page, *Config) (path string, content []byte)
// outputGemini outputs the page as Gemini text. // outputGemini outputs the page as Gemini text.
func outputGemini(p *Page, cfg *Config) (path string, content []byte) { func outputGemini(p *Page, cfg *Config) (path string, content []byte) {
path = p.Path path = p.Path + "index.gmi"
if strings.HasSuffix(path, "/") {
path += "index.gmi"
} else {
path += "/index.gmi"
}
content = []byte(p.Content) content = []byte(p.Content)
return return
} }
// outputHTML outputs the page as HTML. // outputHTML outputs the page as HTML.
func outputHTML(p *Page, cfg *Config) (path string, content []byte) { func outputHTML(p *Page, cfg *Config) (path string, content []byte) {
path = p.Path path = p.Path + "index.html"
if strings.HasSuffix(path, "/") {
path += "index.html"
} else {
path += "/index.html"
}
r := strings.NewReader(p.Content) r := strings.NewReader(p.Content)
text := gemini.ParseText(r) text := gemini.ParseText(r)

View file

@ -56,7 +56,7 @@ func NewPage(path string, content []byte) *Page {
} }
// Remove extension from path // Remove extension from path
page.Path = "/" + strings.TrimSuffix(path, ".gmi") page.Path = "/" + strings.TrimSuffix(path, ".gmi") + "/"
page.Content = string(content) page.Content = string(content)
return &page return &page
} }