Support pages without folders
authorNoah Campbell <noahcampbell@gmail.com>
Sat, 3 Aug 2013 17:51:21 +0000 (10:51 -0700)
committerNoah Campbell <noahcampbell@gmail.com>
Sat, 10 Aug 2013 00:36:31 +0000 (17:36 -0700)
hugolib/page.go
hugolib/path_seperators_test.go [new file with mode: 0644]

index ff00493b212bd4afa8ecacc676649c46621c6b3a..05e40d981be213366baf662cc14a27918b50a9e3 100644 (file)
@@ -92,6 +92,9 @@ func initializePage(filename string) (page Page) {
 
 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
diff --git a/hugolib/path_seperators_test.go b/hugolib/path_seperators_test.go
new file mode 100644 (file)
index 0000000..79f1dd4
--- /dev/null
@@ -0,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)
+}