aboutsummaryrefslogtreecommitdiffhomepage
path: root/hugolib/page__paths.go
diff options
context:
space:
mode:
authorn1xx1 <[email protected]>2024-08-01 12:14:29 +0200
committerGitHub <[email protected]>2024-08-01 12:14:29 +0200
commit566fe7ba12e7ecabadffa9ec76b319d04063c78b (patch)
tree227ffdfe6d1cb203f87f2930b9d892adb243805c /hugolib/page__paths.go
parent92573012e83bf8d71a247027d2f7f7f43a9c42b7 (diff)
downloadhugo-566fe7ba12e7ecabadffa9ec76b319d04063c78b.tar.gz
hugo-566fe7ba12e7ecabadffa9ec76b319d04063c78b.zip
resources/page: Expand parmalinks tokens in `url`
This change allows to use permalink tokens in url front matter fields. This should be useful to target more specific pages instead of using a global permalink configuration. It's expected to be used with cascade. Fixes #9714
Diffstat (limited to 'hugolib/page__paths.go')
-rw-r--r--hugolib/page__paths.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/hugolib/page__paths.go b/hugolib/page__paths.go
index d89388f81..6324b5871 100644
--- a/hugolib/page__paths.go
+++ b/hugolib/page__paths.go
@@ -141,6 +141,19 @@ func createTargetPathDescriptor(p *pageState) (page.TargetPathDescriptor, error)
desc.PrefixFilePath = s.getLanguageTargetPathLang(alwaysInSubDir)
desc.PrefixLink = s.getLanguagePermalinkLang(alwaysInSubDir)
+ if desc.URL != "" && strings.IndexByte(desc.URL, ':') >= 0 {
+ // Attempt to parse and expand an url
+ opath, err := d.ResourceSpec.Permalinks.ExpandPattern(desc.URL, p)
+ if err != nil {
+ return desc, err
+ }
+
+ if opath != "" {
+ opath, _ = url.QueryUnescape(opath)
+ desc.URL = opath
+ }
+ }
+
opath, err := d.ResourceSpec.Permalinks.Expand(p.Section(), p)
if err != nil {
return desc, err