1
0
mirror of https://git.sr.ht/~adnano/kiln synced 2024-11-08 14:19:20 +01:00

Implement support for ugly URLs

This commit is contained in:
adnano 2021-05-10 00:44:25 -04:00
parent ce0b2cff1e
commit d7567ca69f
2 changed files with 17 additions and 15 deletions

@ -4,7 +4,6 @@ import (
"fmt"
"html/template"
"os"
"path"
"strings"
"github.com/BurntSushi/toml"
@ -12,11 +11,11 @@ import (
// Config contains site configuration.
type Config struct {
Title string
URLs []string
Feeds map[string]string
Tasks map[string]*Task
Permalinks map[string]string
Title string `toml:"title"`
URLs []string `toml:"urls"`
Feeds map[string]string `toml:"feeds"`
Tasks map[string]*Task `toml:"tasks"`
Permalinks map[string]string `toml:"permalinks"`
templates *Templates
}
@ -29,10 +28,7 @@ type Task struct {
PostProcess string `toml:"postprocess"` // postprocess command
StaticDir string `toml:"static_dir"` // static file directory
OutputDir string `toml:"output_dir"` // output directory
}
func (t Task) OutputPath(pagePath string) string {
return path.Join(pagePath, "index"+t.OutputExt)
UglyURLs bool `toml:"ugly_urls"` // whether to use ugly URLs
}
// LoadConfig loads the configuration from the provided path.

16
dir.go

@ -125,11 +125,14 @@ func (d *Dir) read(srcDir, path string, task *Task) error {
page.Path = d.Path
d.index = page
} else {
// Remove extension from path
// TODO: Allow using ugly URLs
path = strings.TrimSuffix(path, pathpkg.Ext(path))
path = "/" + strings.TrimSuffix(path, task.InputExt)
if task.UglyURLs {
path += task.OutputExt
} else {
path += "/"
}
page.Name = pathpkg.Base(path)
page.Path = "/" + path + "/"
page.Path = path
d.Pages = append(d.Pages, page)
}
}
@ -216,7 +219,10 @@ func (d *Dir) Write(dstDir string, task *Task) error {
pages = append(pages, d.index)
}
for _, page := range pages {
path := task.OutputPath(page.Path)
path := page.Path
if !task.UglyURLs || page == d.index {
path = pathpkg.Join(path, "index"+task.OutputExt)
}
var content []byte
if cmd := task.PostProcess; cmd != "" {
content = RunProcessCmd(cmd, strings.NewReader(page.Content))