diff options
author | Mai-Lapyst <67418776+Mai-Lapyst@users.noreply.github.com> | 2023-06-26 15:31:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-26 15:31:01 +0200 |
commit | cc14c6a52c215fc43716f7b266c4c340b3d28230 (patch) | |
tree | 0d371fe0f9421d52a42e203ade99127c2d11806d /hugolib/page__paths.go | |
parent | e3308a0bbc2de1cb4d7571521abeab07049ce31f (diff) |
resources/page: Allow section and taxonomy pages to have a permalink configuration
Allows using permalink configuration for sections (branch bundles) and
also for taxonomy pages. Extends the current permalink configuration to
be able to specified per page kind while also staying backward compatible:
all permalink patterns not dedicated to a certain kind, get automatically
added for both normal pages and term pages.
Fixes #8523
Diffstat (limited to 'hugolib/page__paths.go')
-rw-r--r-- | hugolib/page__paths.go | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/hugolib/page__paths.go b/hugolib/page__paths.go index 72eac3182..f98531c10 100644 --- a/hugolib/page__paths.go +++ b/hugolib/page__paths.go @@ -18,6 +18,7 @@ import ( "strings" "github.com/gohugoio/hugo/helpers" + "github.com/gohugoio/hugo/hugofs/files" "github.com/gohugoio/hugo/resources/page" ) @@ -108,14 +109,16 @@ func createTargetPathDescriptor(s *Site, p page.Page, pm *pageMeta) (page.Target ) d := s.Deps + classifier := files.ContentClassZero if !p.File().IsZero() { dir = p.File().Dir() baseName = p.File().TranslationBaseName() contentBaseName = p.File().ContentBaseName() + classifier = p.File().Classifier() } - if baseName != contentBaseName { + if classifier == files.ContentClassLeaf { // See https://github.com/gohugoio/hugo/issues/4870 // A leaf bundle dir = strings.TrimSuffix(dir, contentBaseName+helpers.FilePathSeparator) @@ -143,22 +146,26 @@ func createTargetPathDescriptor(s *Site, p page.Page, pm *pageMeta) (page.Target desc.PrefixFilePath = s.getLanguageTargetPathLang(alwaysInSubDir) desc.PrefixLink = s.getLanguagePermalinkLang(alwaysInSubDir) - // Expand only page.KindPage and page.KindTaxonomy; don't expand other Kinds of Pages - // like page.KindSection or page.KindTaxonomyTerm because they are "shallower" and - // the permalink configuration values are likely to be redundant, e.g. - // naively expanding /category/:slug/ would give /category/categories/ for - // the "categories" page.KindTaxonomyTerm. - if p.Kind() == page.KindPage || p.Kind() == page.KindTerm { - opath, err := d.ResourceSpec.Permalinks.Expand(p.Section(), p) - if err != nil { - return desc, err - } + opath, err := d.ResourceSpec.Permalinks.Expand(p.Section(), p) + if err != nil { + return desc, err + } - if opath != "" { - opath, _ = url.QueryUnescape(opath) - desc.ExpandedPermalink = opath + if opath != "" { + opath, _ = url.QueryUnescape(opath) + if strings.HasSuffix(opath, "//") { + // When rewriting the _index of the section the permalink config is applied to, + // we get douple slashes at the end sometimes; clear them up here + opath = strings.TrimSuffix(opath, "/") } + desc.ExpandedPermalink = opath + + if !p.File().IsZero() { + s.Log.Debugf("Set expanded permalink path for %s %s to %#v", p.Kind(), p.File().Path(), opath) + } else { + s.Log.Debugf("Set expanded permalink path for %s in %v to %#v", p.Kind(), desc.Sections, opath) + } } return desc, nil |