From 19538a1bd6732930977654b9a61c33adbb9e533f Mon Sep 17 00:00:00 2001 From: Noah Campbell Date: Sat, 3 Aug 2013 10:51:21 -0700 Subject: [PATCH] Support pages without folders --- hugolib/page.go | 3 +++ hugolib/path_seperators_test.go | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 hugolib/path_seperators_test.go 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) +}