diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-01-27 18:03:06 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-01-27 19:13:34 +0100 |
commit | 4eb2fec67c3a72a3ac98aa834dc56fd4504626d8 (patch) | |
tree | 80cfebc9fdc0e488b72e6ae2f3a6958953d0c2a1 /source/fileInfo.go | |
parent | 83c761b71a980aee6331179b271c7e24e999e8eb (diff) |
Fix handling of top-level page bundles
Fixes #4332
Diffstat (limited to 'source/fileInfo.go')
-rw-r--r-- | source/fileInfo.go | 17 |
1 files changed, 8 insertions, 9 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 |