@@ -79,19 +79,21 @@ func NewPermalinkExpander(urlize func(uri string) string, patterns map[string]ma
79
79
}
80
80
81
81
p .knownPermalinkAttributes = map [string ]pageToPermaAttribute {
82
- "year" : p .pageToPermalinkDate ,
83
- "month" : p .pageToPermalinkDate ,
84
- "monthname" : p .pageToPermalinkDate ,
85
- "day" : p .pageToPermalinkDate ,
86
- "weekday" : p .pageToPermalinkDate ,
87
- "weekdayname" : p .pageToPermalinkDate ,
88
- "yearday" : p .pageToPermalinkDate ,
89
- "section" : p .pageToPermalinkSection ,
90
- "sections" : p .pageToPermalinkSections ,
91
- "title" : p .pageToPermalinkTitle ,
92
- "slug" : p .pageToPermalinkSlugElseTitle ,
93
- "slugorfilename" : p .pageToPermalinkSlugElseFilename ,
94
- "filename" : p .pageToPermalinkFilename ,
82
+ "year" : p .pageToPermalinkDate ,
83
+ "month" : p .pageToPermalinkDate ,
84
+ "monthname" : p .pageToPermalinkDate ,
85
+ "day" : p .pageToPermalinkDate ,
86
+ "weekday" : p .pageToPermalinkDate ,
87
+ "weekdayname" : p .pageToPermalinkDate ,
88
+ "yearday" : p .pageToPermalinkDate ,
89
+ "section" : p .pageToPermalinkSection ,
90
+ "sections" : p .pageToPermalinkSections ,
91
+ "title" : p .pageToPermalinkTitle ,
92
+ "slug" : p .pageToPermalinkSlugElseTitle ,
93
+ "slugorfilename" : p .pageToPermalinkSlugElseFilename ,
94
+ "filename" : p .pageToPermalinkFilename ,
95
+ "contentbasename" : p .pageToPermalinkContentBaseName ,
96
+ "contentbasenameorslug" : p .pageToPermalinkContentBaseNameOrSlug ,
95
97
}
96
98
97
99
p .expanders = make (map [string ]map [string ]func (Page ) (string , error ))
@@ -307,6 +309,26 @@ func (l PermalinkExpander) pageToPermalinkSections(p Page, _ string) (string, er
307
309
return p .CurrentSection ().SectionsPath (), nil
308
310
}
309
311
312
+ // pageToPermalinkContentBaseName returns the URL-safe form of the content base name.
313
+ func (l PermalinkExpander ) pageToPermalinkContentBaseName (p Page , _ string ) (string , error ) {
314
+ if p .File () == nil {
315
+ return "" , nil
316
+ }
317
+ return l .urlize (p .File ().ContentBaseName ()), nil
318
+ }
319
+
320
+ // pageToPermalinkContentBaseNameOrSlug returns the URL-safe form of the content base name, or the slug.
321
+ func (l PermalinkExpander ) pageToPermalinkContentBaseNameOrSlug (p Page , a string ) (string , error ) {
322
+ name , err := l .pageToPermalinkContentBaseName (p , a )
323
+ if err != nil {
324
+ return "" , nil
325
+ }
326
+ if name != "" {
327
+ return name , nil
328
+ }
329
+ return l .pageToPermalinkSlugElseTitle (p , a )
330
+ }
331
+
310
332
func (l PermalinkExpander ) translationBaseName (p Page ) string {
311
333
if p .File () == nil {
312
334
return ""
0 commit comments