aboutsummaryrefslogtreecommitdiffhomepage
path: root/source
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2018-01-27 18:03:06 +0100
committerBjørn Erik Pedersen <[email protected]>2018-01-27 19:13:34 +0100
commit4eb2fec67c3a72a3ac98aa834dc56fd4504626d8 (patch)
tree80cfebc9fdc0e488b72e6ae2f3a6958953d0c2a1 /source
parent83c761b71a980aee6331179b271c7e24e999e8eb (diff)
downloadhugo-4eb2fec67c3a72a3ac98aa834dc56fd4504626d8.tar.gz
hugo-4eb2fec67c3a72a3ac98aa834dc56fd4504626d8.zip
Fix handling of top-level page bundles
Fixes #4332
Diffstat (limited to 'source')
-rw-r--r--source/fileInfo.go17
-rw-r--r--source/fileInfo_test.go7
-rw-r--r--source/filesystem.go2
3 files changed, 15 insertions, 11 deletions
diff --git a/source/fileInfo.go b/source/fileInfo.go
index a20ba27e5..eb7015aa1 100644
--- a/source/fileInfo.go
+++ b/source/fileInfo.go
@@ -54,6 +54,7 @@ type File interface {
LogicalName() string
// Section is first directory below the content root.
+ // For page bundles in root, the Section will be empty.
Section() string
// BaseFileName is a filename without extension.
@@ -99,6 +100,7 @@ type FileInfo struct {
baseName string
translationBaseName string
section string
+ isLeafBundle bool
uniqueID string
@@ -142,16 +144,12 @@ func (fi *FileInfo) String() string { return fi.BaseFileName() }
// in some cases that is slightly expensive to construct.
func (fi *FileInfo) init() {
fi.lazyInit.Do(func() {
- parts := strings.Split(fi.relDir, helpers.FilePathSeparator)
+ relDir := strings.Trim(fi.relDir, helpers.FilePathSeparator)
+ parts := strings.Split(relDir, helpers.FilePathSeparator)
+
var section string
- if len(parts) == 1 {
+ if (!fi.isLeafBundle && len(parts) == 1) || len(parts) > 1 {
section = parts[0]
- } else if len(parts) > 1 {
- if parts[0] == "" {
- section = parts[1]
- } else {
- section = parts[0]
- }
}
fi.section = section
@@ -161,7 +159,7 @@ func (fi *FileInfo) init() {
})
}
-func (sp *SourceSpec) NewFileInfo(baseDir, filename string, fi os.FileInfo) *FileInfo {
+func (sp *SourceSpec) NewFileInfo(baseDir, filename string, isLeafBundle bool, fi os.FileInfo) *FileInfo {
dir, name := filepath.Split(filename)
if !strings.HasSuffix(dir, helpers.FilePathSeparator) {
@@ -204,6 +202,7 @@ func (sp *SourceSpec) NewFileInfo(baseDir, filename string, fi os.FileInfo) *Fil
name: name,
baseName: baseName,
translationBaseName: translationBaseName,
+ isLeafBundle: isLeafBundle,
}
return f
diff --git a/source/fileInfo_test.go b/source/fileInfo_test.go
index 8ce8c16ef..1b9b130e4 100644
--- a/source/fileInfo_test.go
+++ b/source/fileInfo_test.go
@@ -34,10 +34,15 @@ func TestFileInfo(t *testing.T) {
assert.Equal(filepath.FromSlash("/a/b/page.md"), f.Filename())
assert.Equal(filepath.FromSlash("b/"), f.Dir())
assert.Equal(filepath.FromSlash("b/page.md"), f.Path())
+ assert.Equal("b", f.Section())
+
+ }},
+ {filepath.FromSlash("/a/"), filepath.FromSlash("/a/b/c/d/page.md"), func(f *FileInfo) {
+ assert.Equal("b", f.Section())
}},
} {
- f := s.NewFileInfo(this.base, this.filename, nil)
+ f := s.NewFileInfo(this.base, this.filename, false, nil)
this.assert(f)
}
diff --git a/source/filesystem.go b/source/filesystem.go
index a5f2988e9..db004d3a1 100644
--- a/source/filesystem.go
+++ b/source/filesystem.go
@@ -57,7 +57,7 @@ func (f *Filesystem) add(name string, fi os.FileInfo) (err error) {
name = norm.NFC.String(name)
}
- file = f.SourceSpec.NewFileInfo(f.Base, name, fi)
+ file = f.SourceSpec.NewFileInfo(f.Base, name, false, fi)
f.files = append(f.files, file)
return err