diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-06-18 10:27:27 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2021-06-18 10:55:00 +0200 |
commit | 93aad3c543828efca2adeb7f96cf50ae29878593 (patch) | |
tree | 6a3dd4f6f878f8f36be9cef03a15b78b19d1f3da /resources | |
parent | 5af045ebab109d3e5501b8b6d9fd448840c96c9a (diff) |
Split out the puthe path/filepath functions into common/paths
So they can be used from the config package without cyclic troubles.
Updates #8654
Diffstat (limited to 'resources')
-rw-r--r-- | resources/image.go | 6 | ||||
-rw-r--r-- | resources/image_test.go | 4 | ||||
-rw-r--r-- | resources/page/pagemeta/page_frontmatter.go | 4 | ||||
-rw-r--r-- | resources/transform.go | 6 |
4 files changed, 14 insertions, 6 deletions
diff --git a/resources/image.go b/resources/image.go index 282f008ed..4aec6bed5 100644 --- a/resources/image.go +++ b/resources/image.go @@ -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() } diff --git a/resources/image_test.go b/resources/image_test.go index cca961ee0..e39e88992 100644 --- a/resources/image_test.go +++ b/resources/image_test.go @@ -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) } diff --git a/resources/page/pagemeta/page_frontmatter.go b/resources/page/pagemeta/page_frontmatter.go index a32fc5884..3184b444d 100644 --- a/resources/page/pagemeta/page_frontmatter.go +++ b/resources/page/pagemeta/page_frontmatter.go @@ -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. diff --git a/resources/transform.go b/resources/transform.go index ad2485716..3586a8bfa 100644 --- a/resources/transform.go +++ b/resources/transform.go @@ -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)) } |