mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-15 20:44:01 +02:00
@@ -162,9 +162,12 @@ func (fi *FileInfo) init() {
|
||||
}
|
||||
|
||||
func (sp *SourceSpec) NewFileInfo(baseDir, filename string, fi os.FileInfo) *FileInfo {
|
||||
dir, name := filepath.Split(filename)
|
||||
|
||||
dir = strings.TrimSuffix(dir, helpers.FilePathSeparator)
|
||||
dir, name := filepath.Split(filename)
|
||||
if !strings.HasSuffix(dir, helpers.FilePathSeparator) {
|
||||
dir = dir + helpers.FilePathSeparator
|
||||
}
|
||||
|
||||
baseDir = strings.TrimSuffix(baseDir, helpers.FilePathSeparator)
|
||||
|
||||
relDir := ""
|
||||
|
@@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user