diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-06-12 19:14:29 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-06-13 11:42:32 +0200 |
commit | 1f26420d392a5ab4c7b7fe1911c0268b45d01ab8 (patch) | |
tree | 30453df7f0289f03b9cb36d0e932f4998e141b39 /hugolib/permalinks.go | |
parent | ff54b6bddcefab45339d8dc2b13776b92bdc04b9 (diff) |
hugolib: Support sub-sections in permalink settings
This enables both the variants below:
Current (first level only):
```
"blog": ":section/:title",
```
Nested (all levels):
```
"blog": ":sections/:title",
```
Should ideally been part of Hugo 0.22, but better late than never ...
Fixes #3580
Diffstat (limited to 'hugolib/permalinks.go')
-rw-r--r-- | hugolib/permalinks.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/hugolib/permalinks.go b/hugolib/permalinks.go index 959386419..6f26f098a 100644 --- a/hugolib/permalinks.go +++ b/hugolib/permalinks.go @@ -16,6 +16,7 @@ package hugolib import ( "errors" "fmt" + "path" "regexp" "strconv" "strings" @@ -182,6 +183,12 @@ func pageToPermalinkSection(p *Page, _ string) (string, error) { return p.Section(), nil } +func pageToPermalinkSections(p *Page, _ string) (string, error) { + // TODO(bep) we have some superflous URLize in this file, but let's + // deal with that later. + return path.Join(p.current().sections...), nil +} + func init() { knownPermalinkAttributes = map[string]pageToPermaAttribute{ "year": pageToPermalinkDate, @@ -192,6 +199,7 @@ func init() { "weekdayname": pageToPermalinkDate, "yearday": pageToPermalinkDate, "section": pageToPermalinkSection, + "sections": pageToPermalinkSections, "title": pageToPermalinkTitle, "slug": pageToPermalinkSlugElseTitle, "filename": pageToPermalinkFilename, |