Allow to use filename in permalinks
authorLorenzo Bolla <lorenzo.bolla@yougov.com>
Tue, 27 May 2014 08:14:05 +0000 (09:14 +0100)
committerspf13 <steve.francia@gmail.com>
Wed, 28 May 2014 21:59:49 +0000 (17:59 -0400)
hugolib/permalinks.go

index f6c2ec80de9e0e1b5db4a58fb852c0febfae68eb..ba0842cfbbb564a740f14ca6baac46cd679accff 100644 (file)
@@ -3,6 +3,7 @@ package hugolib
 import (
        "errors"
        "fmt"
+       "path/filepath"
        "strconv"
        "strings"
 
@@ -117,6 +118,13 @@ func pageToPermalinkTitle(p *Page, _ string) (string, error) {
        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
 func pageToPermalinkSlugElseTitle(p *Page, a string) (string, error) {
        if p.Slug != "" {
@@ -142,5 +150,6 @@ func init() {
                "section":     pageToPermalinkSection,
                "title":       pageToPermalinkTitle,
                "slug":        pageToPermalinkSlugElseTitle,
+               "filename":    pageToPermalinkFilename,
        }
 }