From 6bf010fed432e5574e19fd2946ee6397d895950e Mon Sep 17 00:00:00 2001 From: Bjørn Erik Pedersen Date: Thu, 9 Mar 2017 19:19:29 +0100 Subject: hugolib: Refactor/-work the permalink/target path logic This is a pretty fundamental change in Hugo, but absolutely needed if we should have any hope of getting "multiple outputs" done. This commit's goal is to say: * Every file target path is created by `createTargetPath`, i.e. one function for all. * That function takes every page and site parameter into account, to avoid fragile string parsing to uglify etc. later on. * The path creation logic has full test coverage. * All permalinks, paginator URLs etc. are then built on top of that same logic. Fixes #1252 Fixes #2110 Closes #2374 Fixes #1885 Fixes #3102 Fixes #3179 Fixes #1641 Fixes #1989 --- helpers/pathspec.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'helpers/pathspec.go') diff --git a/helpers/pathspec.go b/helpers/pathspec.go index ddc183380..ffca4df8e 100644 --- a/helpers/pathspec.go +++ b/helpers/pathspec.go @@ -22,6 +22,8 @@ import ( // PathSpec holds methods that decides how paths in URLs and files in Hugo should look like. type PathSpec struct { + BaseURL + disablePathToLower bool removePathAccents bool uglyURLs bool @@ -32,8 +34,7 @@ type PathSpec struct { // pagination path handling paginatePath string - baseURL string - theme string + theme string // Directories themesDir string @@ -61,6 +62,9 @@ func (p PathSpec) String() string { // NewPathSpec creats a new PathSpec from the given filesystems and Language. func NewPathSpec(fs *hugofs.Fs, cfg config.Provider) *PathSpec { + // TODO(bep) output error handling + baseURL, _ := newBaseURLFromString(cfg.GetString("baseURL")) + ps := &PathSpec{ fs: fs, disablePathToLower: cfg.GetBool("disablePathToLower"), @@ -71,7 +75,7 @@ func NewPathSpec(fs *hugofs.Fs, cfg config.Provider) *PathSpec { defaultContentLanguageInSubdir: cfg.GetBool("defaultContentLanguageInSubdir"), defaultContentLanguage: cfg.GetString("defaultContentLanguage"), paginatePath: cfg.GetString("paginatePath"), - baseURL: cfg.GetString("baseURL"), + BaseURL: baseURL, themesDir: cfg.GetString("themesDir"), layoutDir: cfg.GetString("layoutDir"), workingDir: cfg.GetString("workingDir"), -- cgit v1.2.3