Support pages without folders

This commit is contained in:
Noah Campbell 2013-08-03 10:51:21 -07:00
parent fc5e92cc24
commit 19538a1bd6
2 changed files with 22 additions and 0 deletions

View 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

View file

@ -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)
}