hugo

Unnamed repository; edit this file 'description' to name the repository.

git clone git://git.shimmy1996.com/hugo.git
commit e98f0014f2f46ff4b342d5eb3062d4fb1e6d4184
parent d65061dffb6e9ff4afb1a683181a84cefdfedfd3
Author: Lorenzo Bolla <lorenzo.bolla@yougov.com>
Date:   Tue, 27 May 2014 09:14:05 +0100

Allow to use filename in permalinks

Diffstat:
Mhugolib/permalinks.go | 9+++++++++
1 file changed, 9 insertions(+), 0 deletions(-)
diff --git a/hugolib/permalinks.go b/hugolib/permalinks.go
@@ -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,
 	}
 }