From d7567ca69f251170644c0ddc630ab9bd18577972 Mon Sep 17 00:00:00 2001 From: adnano Date: Mon, 10 May 2021 00:44:25 -0400 Subject: [PATCH] Implement support for ugly URLs --- config.go | 16 ++++++---------- dir.go | 16 +++++++++++----- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/config.go b/config.go index 380b2e7..366b6f3 100644 --- a/config.go +++ b/config.go @@ -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. diff --git a/dir.go b/dir.go index bb12891..6d45581 100644 --- a/dir.go +++ b/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))