Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve resource paths #4501

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions resource/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func (i *Image) doWithImageConfig(action, spec string, f func(src image.Image, c
}
}

key := i.relTargetPathForRel(i.filenameFromConfig(conf), false)
key := i.filenameFromConfig(conf)

return i.spec.imageCache.getOrCreate(i, key, func(resourceCacheFilename string) (*Image, error) {
ci := i.clone()
Expand Down Expand Up @@ -579,6 +579,7 @@ func (i *Image) setBasePath(conf imageConfig) {

func (i *Image) filenameFromConfig(conf imageConfig) string {
p1, p2 := helpers.FileAndExt(i.relTargetPath)
path := i.relTargetPath[0:strings.LastIndex(i.relTargetPath, p1)]
idStr := fmt.Sprintf("_hu%s_%d", i.hash, i.osFileInfo.Size())

// Do not change for no good reason.
Expand All @@ -605,7 +606,7 @@ func (i *Image) filenameFromConfig(conf imageConfig) string {
idStr = ""
}

return fmt.Sprintf("%s%s_%s%s", p1, idStr, key, p2)
return fmt.Sprintf("%s%s%s_%s%s", path, p1, idStr, key, p2)
}

func decodeImaging(m map[string]interface{}) (Imaging, error) {
Expand Down
3 changes: 2 additions & 1 deletion resource/testhelpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ func fetchResourceForSpec(spec *Spec, assert *require.Assertions, name string) R
return r
}
func assertFileCache(assert *require.Assertions, fs *hugofs.Fs, filename string, width, height int) {
f, err := fs.Source.Open(filepath.Join("/res/_gen/images", filename))
p := filepath.Join("/res/_gen/images", path.Base(filename))
f, err := fs.Source.Open(p)
assert.NoError(err)
defer f.Close()

Expand Down