summaryrefslogtreecommitdiffstats
path: root/resources/page/permalinks.go
diff options
context:
space:
mode:
authorDawid Potocki <dawid@dawidpotocki.com>2022-06-14 00:22:58 +1200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-06-13 21:45:03 +0200
commit5a9ecb82a39886a7241ec656fc980f20c1b8dd1c (patch)
tree6f1f6a374bf2b6de5dcffd91c38790f95923f71c /resources/page/permalinks.go
parentcbc35c48d252a1b44e4c30e26cfba2ff462a1f96 (diff)
resources/page: Add :slugorfilename attribute
Fixes #4739, #385
Diffstat (limited to 'resources/page/permalinks.go')
-rw-r--r--resources/page/permalinks.go33
1 files changed, 21 insertions, 12 deletions
diff --git a/resources/page/permalinks.go b/resources/page/permalinks.go
index cd9c1dc15..c31d22a3c 100644
--- a/resources/page/permalinks.go
+++ b/resources/page/permalinks.go
@@ -72,18 +72,19 @@ func NewPermalinkExpander(ps *helpers.PathSpec) (PermalinkExpander, error) {
p := PermalinkExpander{ps: ps}
p.knownPermalinkAttributes = map[string]pageToPermaAttribute{
- "year": p.pageToPermalinkDate,
- "month": p.pageToPermalinkDate,
- "monthname": p.pageToPermalinkDate,
- "day": p.pageToPermalinkDate,
- "weekday": p.pageToPermalinkDate,
- "weekdayname": p.pageToPermalinkDate,
- "yearday": p.pageToPermalinkDate,
- "section": p.pageToPermalinkSection,
- "sections": p.pageToPermalinkSections,
- "title": p.pageToPermalinkTitle,
- "slug": p.pageToPermalinkSlugElseTitle,
- "filename": p.pageToPermalinkFilename,
+ "year": p.pageToPermalinkDate,
+ "month": p.pageToPermalinkDate,
+ "monthname": p.pageToPermalinkDate,
+ "day": p.pageToPermalinkDate,
+ "weekday": p.pageToPermalinkDate,
+ "weekdayname": p.pageToPermalinkDate,
+ "yearday": p.pageToPermalinkDate,
+ "section": p.pageToPermalinkSection,
+ "sections": p.pageToPermalinkSections,
+ "title": p.pageToPermalinkTitle,
+ "slug": p.pageToPermalinkSlugElseTitle,
+ "slugorfilename": p.pageToPermalinkSlugElseFilename,
+ "filename": p.pageToPermalinkFilename,
}
patterns := ps.Cfg.GetStringMapString("permalinks")
@@ -266,6 +267,14 @@ func (l PermalinkExpander) pageToPermalinkSlugElseTitle(p Page, a string) (strin
return l.pageToPermalinkTitle(p, a)
}
+// if the page has a slug, return the slug, else return the filename
+func (l PermalinkExpander) pageToPermalinkSlugElseFilename(p Page, a string) (string, error) {
+ if p.Slug() != "" {
+ return l.ps.URLize(p.Slug()), nil
+ }
+ return l.pageToPermalinkFilename(p, a)
+}
+
func (l PermalinkExpander) pageToPermalinkSection(p Page, _ string) (string, error) {
return p.Section(), nil
}