Fixed bug where Url specified in front matter as pretty url wouldnt render - hugo - [fork] hugo port for 9front
HTML git clone git@git.drkhsh.at/hugo.git
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
DIR commit 4ed43e8076f43bfab371868f6986f583381190b4
DIR parent 71678a7183bd9b90f121d9116d1363fe8f914045
HTML Author: Mark Sanborn <marcrosoft@gmail.com>
Date: Thu, 29 Aug 2013 09:37:37 -0700
Fixed bug where Url specified in front matter as pretty url wouldnt render
Signed-off-by: Noah Campbell <noahcampbell@gmail.com>
Diffstat:
M hugolib/site.go | 4 ++++
M hugolib/site_test.go | 18 ++++++++++++++++++
2 files changed, 22 insertions(+), 0 deletions(-)
---
DIR diff --git a/hugolib/site.go b/hugolib/site.go
@@ -332,6 +332,10 @@ func (s *Site) setOutFile(p *Page) {
// Always use Url if it's specified
if len(strings.TrimSpace(p.Url)) > 2 {
p.OutFile = strings.TrimSpace(p.Url)
+
+ if strings.HasSuffix(p.OutFile, "/") {
+ p.OutFile = p.OutFile + "index.html"
+ }
return
}
DIR diff --git a/hugolib/site_test.go b/hugolib/site_test.go
@@ -16,6 +16,12 @@ content`
var TEMPLATE_MISSING_FUNC = "{{ .Title | funcdoesnotexists }}"
var TEMPLATE_FUNC = "{{ .Title | urlize }}"
+var PAGE_URL_SPECIFIED = `---
+title: simple template
+url: "mycategory/my-whatever-content/"
+---
+content`
+
func pageMust(p *Page, err error) *Page {
if err != nil {
panic(err)
@@ -159,3 +165,15 @@ func TestRenderThingOrDefault(t *testing.T) {
t.Errorf("Content does not match. Expected '%s', got '%s'", test.expected, html)
}
}}
+
+func TestSetOutFile(t *testing.T) {
+ s := new(Site)
+ p := pageMust(ReadFrom(strings.NewReader(PAGE_URL_SPECIFIED), "content/a/file.md"))
+ s.setOutFile(p)
+
+ expected := "mycategory/my-whatever-content/index.html"
+
+ if p.OutFile != "mycategory/my-whatever-content/index.html" {
+ t.Errorf("Outfile does not match. Expected '%s', got '%s'", expected, p.OutFile)
+ }
+}