diff --git a/hugolib/page.go b/hugolib/page.go index ff00493b2..05e40d981 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -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 index 000000000..79f1dd46b --- /dev/null +++ b/hugolib/path_seperators_test.go @@ -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) +}