summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--hugolib/page.go15
-rw-r--r--hugolib/page_bundler_test.go1
-rw-r--r--hugolib/permalinks.go5
-rw-r--r--source/fileInfo.go5
-rw-r--r--source/fileInfo_test.go22
5 files changed, 34 insertions, 14 deletions
diff --git a/hugolib/page.go b/hugolib/page.go
index 76151060c..d589ffcc1 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -1940,18 +1940,11 @@ func (p *Page) addLangPathPrefixIfFlagSet(outfile string, should bool) string {
}
func sectionsFromDir(dirname string) []string {
- sections := strings.Split(dirname, helpers.FilePathSeparator)
- if len(sections) == 1 {
- if sections[0] == "" {
- return nil
- }
- return sections
- }
- if len(sections) > 1 && sections[0] == "" {
- return sections[1:]
+ dirname = strings.Trim(dirname, helpers.FilePathSeparator)
+ if dirname == "" {
+ return nil
}
-
- return sections
+ return strings.Split(dirname, helpers.FilePathSeparator)
}
const (
diff --git a/hugolib/page_bundler_test.go b/hugolib/page_bundler_test.go
index ff50fc67a..ab629d6ad 100644
--- a/hugolib/page_bundler_test.go
+++ b/hugolib/page_bundler_test.go
@@ -134,7 +134,6 @@ func TestPageBundlerSite(t *testing.T) {
th.assertFileContent(filepath.FromSlash("/work/public/cpath/2017/pageslug/cindex.html"), "TheContent")
assert.Equal("/a/b/", leafBundle2.RelPermalink())
-
}
})
diff --git a/hugolib/permalinks.go b/hugolib/permalinks.go
index 8f64614b8..9f3a21079 100644
--- a/hugolib/permalinks.go
+++ b/hugolib/permalinks.go
@@ -21,6 +21,8 @@ import (
"regexp"
"strconv"
"strings"
+
+ "github.com/gohugoio/hugo/helpers"
)
// pathPattern represents a string which builds up a URL from attributes
@@ -160,7 +162,8 @@ func pageToPermalinkFilename(p *Page, _ string) (string, error) {
name := p.File.TranslationBaseName()
if name == "index" {
// Page bundles; the directory name will hopefully have a better name.
- _, name = filepath.Split(p.File.Dir())
+ dir := strings.TrimSuffix(p.File.Dir(), helpers.FilePathSeparator)
+ _, name = filepath.Split(dir)
}
return p.s.PathSpec.URLize(name), nil
diff --git a/source/fileInfo.go b/source/fileInfo.go
index e4b4a80fb..a20ba27e5 100644
--- a/source/fileInfo.go
+++ b/source/fileInfo.go
@@ -162,9 +162,12 @@ func (fi *FileInfo) init() {
}
func (sp *SourceSpec) NewFileInfo(baseDir, filename string, fi os.FileInfo) *FileInfo {
+
dir, name := filepath.Split(filename)
+ if !strings.HasSuffix(dir, helpers.FilePathSeparator) {
+ dir = dir + helpers.FilePathSeparator
+ }
- dir = strings.TrimSuffix(dir, helpers.FilePathSeparator)
baseDir = strings.TrimSuffix(baseDir, helpers.FilePathSeparator)
relDir := ""
diff --git a/source/fileInfo_test.go b/source/fileInfo_test.go
index 3f99497ad..1d7c86ec2 100644
--- a/source/fileInfo_test.go
+++ b/source/fileInfo_test.go
@@ -14,9 +14,31 @@
package source
import (
+ "path/filepath"
"testing"
+
+ "github.com/stretchr/testify/require"
)
func TestFileInfo(t *testing.T) {
+ assert := require.New(t)
+
+ s := newTestSourceSpec()
+
+ for _, this := range []struct {
+ base string
+ filename string
+ assert func(f *FileInfo)
+ }{
+ {"/a/", filepath.FromSlash("/a/b/page.md"), func(f *FileInfo) {
+ 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())
+
+ }},
+ } {
+ f := s.NewFileInfo(this.base, this.filename, nil)
+ this.assert(f)
+ }
}