mirror of
https://github.com/gohugoio/hugo.git
synced 2025-03-19 15:33:09 +00:00
Allow to use filename in permalinks
This commit is contained in:
parent
d65061dffb
commit
e98f0014f2
1 changed files with 9 additions and 0 deletions
|
@ -3,6 +3,7 @@ package hugolib
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -117,6 +118,13 @@ func pageToPermalinkTitle(p *Page, _ string) (string, error) {
|
||||||
return helpers.Urlize(p.Title), nil
|
return helpers.Urlize(p.Title), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// pageToPermalinkFilename returns the URL-safe form of the filename
|
||||||
|
func pageToPermalinkFilename(p *Page, _ string) (string, error) {
|
||||||
|
var extension = filepath.Ext(p.FileName)
|
||||||
|
var name = p.FileName[0 : len(p.FileName)-len(extension)]
|
||||||
|
return helpers.Urlize(name), nil
|
||||||
|
}
|
||||||
|
|
||||||
// if the page has a slug, return the slug, else return the title
|
// if the page has a slug, return the slug, else return the title
|
||||||
func pageToPermalinkSlugElseTitle(p *Page, a string) (string, error) {
|
func pageToPermalinkSlugElseTitle(p *Page, a string) (string, error) {
|
||||||
if p.Slug != "" {
|
if p.Slug != "" {
|
||||||
|
@ -142,5 +150,6 @@ func init() {
|
||||||
"section": pageToPermalinkSection,
|
"section": pageToPermalinkSection,
|
||||||
"title": pageToPermalinkTitle,
|
"title": pageToPermalinkTitle,
|
||||||
"slug": pageToPermalinkSlugElseTitle,
|
"slug": pageToPermalinkSlugElseTitle,
|
||||||
|
"filename": pageToPermalinkFilename,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue