Split out the puthe path/filepath functions into common/paths

So they can be used from the config package without cyclic troubles.

Updates #8654
This commit is contained in:
Bjørn Erik Pedersen
2021-06-18 10:27:27 +02:00
parent 5af045ebab
commit 93aad3c543
21 changed files with 956 additions and 591 deletions

View File

@@ -29,6 +29,8 @@ import (
"strings"
"sync"
"github.com/gohugoio/hugo/common/paths"
"github.com/disintegration/gift"
"github.com/gohugoio/hugo/cache/filecache"
@@ -365,7 +367,7 @@ func (i *imageResource) getImageMetaCacheTargetPath() string {
if fi := i.getFileInfo(); fi != nil {
df.dir = filepath.Dir(fi.Meta().Path())
}
p1, _ := helpers.FileAndExt(df.file)
p1, _ := paths.FileAndExt(df.file)
h, _ := i.hash()
idStr := helpers.HashString(h, i.size(), imageMetaVersionNumber, cfgHash)
p := path.Join(df.dir, fmt.Sprintf("%s_%s.json", p1, idStr))
@@ -373,7 +375,7 @@ func (i *imageResource) getImageMetaCacheTargetPath() string {
}
func (i *imageResource) relTargetPathFromConfig(conf images.ImageConfig) dirFile {
p1, p2 := helpers.FileAndExt(i.getResourcePaths().relTargetDirFile.file)
p1, p2 := paths.FileAndExt(i.getResourcePaths().relTargetDirFile.file)
if conf.TargetFormat != i.Format {
p2 = conf.TargetFormat.DefaultExtension()
}

View File

@@ -28,6 +28,8 @@ import (
"testing"
"time"
"github.com/gohugoio/hugo/common/paths"
"github.com/spf13/afero"
"github.com/disintegration/gift"
@@ -145,7 +147,7 @@ func TestImageTransformFormat(t *testing.T) {
assertExtWidthHeight := func(img resource.Image, ext string, w, h int) {
c.Helper()
c.Assert(img, qt.Not(qt.IsNil))
c.Assert(helpers.Ext(img.RelPermalink()), qt.Equals, ext)
c.Assert(paths.Ext(img.RelPermalink()), qt.Equals, ext)
c.Assert(img.Width(), qt.Equals, w)
c.Assert(img.Height(), qt.Equals, h)
}

View File

@@ -17,6 +17,8 @@ import (
"strings"
"time"
"github.com/gohugoio/hugo/common/paths"
"github.com/gohugoio/hugo/common/loggers"
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/resources/resource"
@@ -118,7 +120,7 @@ func (f FrontMatterHandler) IsDateKey(key string) bool {
// This follows the format as outlined in Jekyll, https://jekyllrb.com/docs/posts/:
// "Where YEAR is a four-digit number, MONTH and DAY are both two-digit numbers"
func dateAndSlugFromBaseFilename(name string) (time.Time, string) {
withoutExt, _ := helpers.FileAndExt(name)
withoutExt, _ := paths.FileAndExt(name)
if len(withoutExt) < 10 {
// This can not be a date.

View File

@@ -22,6 +22,8 @@ import (
"strings"
"sync"
"github.com/gohugoio/hugo/common/paths"
"github.com/pkg/errors"
"github.com/gohugoio/hugo/resources/images/exif"
@@ -136,13 +138,13 @@ func (ctx *ResourceTransformationCtx) PublishSourceMap(content string) error {
// extension, e.g. ".scss"
func (ctx *ResourceTransformationCtx) ReplaceOutPathExtension(newExt string) {
dir, file := path.Split(ctx.InPath)
base, _ := helpers.PathAndExt(file)
base, _ := paths.PathAndExt(file)
ctx.OutPath = path.Join(dir, (base + newExt))
}
func (ctx *ResourceTransformationCtx) addPathIdentifier(inPath, identifier string) string {
dir, file := path.Split(inPath)
base, ext := helpers.PathAndExt(file)
base, ext := paths.PathAndExt(file)
return path.Join(dir, (base + identifier + ext))
}