shithub: hugo

Download patch

ref: 19538a1bd6732930977654b9a61c33adbb9e533f
parent: fc5e92cc247b2414bff70dfe5e82ac897eddb280
author: Noah Campbell <[email protected]>
date: Sat Aug 3 06:51:21 EDT 2013

Support pages without folders

--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -92,6 +92,9 @@
 
 func (p *Page) setSection() {
 	x := strings.Split(p.FileName, string(os.PathSeparator))
+	if len(x) <= 1 {
+		return
+	}
 
 	if section := x[len(x)-2]; section != "content" {
 		p.Section = section
--- /dev/null
+++ b/hugolib/path_seperators_test.go
@@ -1,0 +1,19 @@
+package hugolib
+
+import (
+	"testing"
+	"path/filepath"
+)
+
+func TestDegenerateMissingFolderInPageFilename(t *testing.T) {
+	p := NewPage(filepath.Join("foobar"))
+	if p != nil {
+		t.Fatalf("Creating a new Page without a subdirectory should result in nil page")
+	}
+}
+
+func TestSettingOutFileOnPageContainsCorrectSlashes(t *testing.T) {
+	s := NewSite(&Config{})
+	p := NewPage(filepath.Join("sub", "foobar"))
+	s.setOutFile(p)
+}