How to Instruct Hugo Pipe not To Build Caches into public/ Directory?

How to tell/redirect image processing resources from bundling its caches into the output folder?


My image processor partial function:

...
{{- $ret = resources.GetMatch $v.Source -}}
{{- if $ret -}}
        {{- if $v.Resize -}}
                {{- $ret = $original.Resize $data.Dimension -}}
        {{- end -}}
        {{- $ret = resources.Copy $data.Filename $ret -}}
        {{- $data = merge $data (dict "URL" $ret.Permalink) -}}
        ...
{{- end -}}
...

It did build the output favicons image files as intended, shown as follows, along its cache directory called images/, where the cache directory was explicitly instructed to be outside of the destination directory:

(Build command: hugo --cacheDir "..." --cleanDestinationDir --forceSyncStatic --minify --destination "...")

drwxr-xr-x 6 u0 u0  4096 Jul 30 18:25 .
drwxr-xr-x 4 u0 u0  4096 Jul 30 18:25 ..
-rw-r--r-- 1 u0 u0  3169 Jul 30 18:25 404.html
-rw-r--r-- 1 u0 u0  5258 Jul 30 18:25 apple-icon-114x114.png
-rw-r--r-- 1 u0 u0  5571 Jul 30 18:25 apple-icon-120x120.png
-rw-r--r-- 1 u0 u0  6856 Jul 30 18:25 apple-icon-144x144.png
-rw-r--r-- 1 u0 u0  7260 Jul 30 18:25 apple-icon-152x152.png
-rw-r--r-- 1 u0 u0  8663 Jul 30 18:25 apple-icon-180x180.png
-rw-r--r-- 1 u0 u0  2398 Jul 30 18:25 apple-icon-57x57.png
-rw-r--r-- 1 u0 u0  2501 Jul 30 18:25 apple-icon-60x60.png
-rw-r--r-- 1 u0 u0  3221 Jul 30 18:25 apple-icon-72x72.png
-rw-r--r-- 1 u0 u0  3316 Jul 30 18:25 apple-icon-76x76.png
drwxr-xr-x 5 u0 u0  4096 Jul 30 18:25 en/
-rw-r--r-- 1 u0 u0   588 Jul 30 18:25 favicon-icon-16x16.png
-rw-r--r-- 1 u0 u0  9666 Jul 30 18:25 favicon-icon-192x192.png
-rw-r--r-- 1 u0 u0  1227 Jul 30 18:25 favicon-icon-32x32.png
-rw-r--r-- 1 u0 u0 27716 Jul 30 18:25 favicon-icon-512x512.png
-rw-r--r-- 1 u0 u0  4611 Jul 30 18:25 favicon-icon-96x96.png
drwxr-xr-x 2 u0 u0  4096 Jul 30 18:25 images/
-rw-r--r-- 1 u0 u0   279 Jul 30 18:25 index.html
-rw-r--r-- 1 u0 u0  6948 Jul 30 18:25 ms-icon-144x144.png
-rw------- 1 u0 u0     9 Jul 30 18:25 .nojekyll
-rw-r--r-- 1 u0 u0    86 Jul 30 18:25 robots.txt
-rw-r--r-- 1 u0 u0  8663 Jul 30 18:25 safari-pinned-tab.svg
-rw-r--r-- 1 u0 u0   327 Jul 30 18:25 sitemap.xml
drwxr-xr-x 2 u0 u0  4096 Jul 27 11:42 thumbnails/
drwxr-xr-x 4 u0 u0  4096 Jul 30 18:25 zh-hans/

When I attempt to build with --ignore-cache to remove that image/ cache directory off the publication directory, some of the favicon images failed to process at all (0 in size):

(Build command: hugo --cacheDir "..." --ignoreCache --cleanDestinationDir --forceSyncStatic --minify --destination "...")

drwxr-xr-x 5 u0 u0  4096 Jul 30 18:34 .
drwxr-xr-x 4 u0 u0  4096 Jul 30 18:34 ..
-rw-r--r-- 1 u0 u0  3169 Jul 30 18:34 404.html
-rw-r--r-- 1 u0 u0     0 Jul 30 18:34 apple-icon-114x114.png
-rw-r--r-- 1 u0 u0     0 Jul 30 18:34 apple-icon-120x120.png
-rw-r--r-- 1 u0 u0     0 Jul 30 18:34 apple-icon-144x144.png
-rw-r--r-- 1 u0 u0     0 Jul 30 18:34 apple-icon-152x152.png
-rw-r--r-- 1 u0 u0     0 Jul 30 18:34 apple-icon-180x180.png
-rw-r--r-- 1 u0 u0     0 Jul 30 18:34 apple-icon-57x57.png
-rw-r--r-- 1 u0 u0  2501 Jul 30 18:34 apple-icon-60x60.png
-rw-r--r-- 1 u0 u0     0 Jul 30 18:34 apple-icon-72x72.png
-rw-r--r-- 1 u0 u0  3316 Jul 30 18:34 apple-icon-76x76.png
drwxr-xr-x 5 u0 u0  4096 Jul 30 18:34 en
-rw-r--r-- 1 u0 u0     0 Jul 30 18:34 favicon-icon-16x16.png
-rw-r--r-- 1 u0 u0     0 Jul 30 18:34 favicon-icon-192x192.png
-rw-r--r-- 1 u0 u0     0 Jul 30 18:34 favicon-icon-32x32.png
-rw-r--r-- 1 u0 u0 27716 Jul 30 18:34 favicon-icon-512x512.png
-rw-r--r-- 1 u0 u0     0 Jul 30 18:34 favicon-icon-96x96.png
-rw-r--r-- 1 u0 u0   279 Jul 30 18:34 index.html
-rw-r--r-- 1 u0 u0     0 Jul 30 18:34 ms-icon-144x144.png
-rw------- 1 u0 u0     9 Jul 30 18:34 .nojekyll
-rw-r--r-- 1 u0 u0    86 Jul 30 18:34 robots.txt
-rw-r--r-- 1 u0 u0     0 Jul 30 18:34 safari-pinned-tab.svg
-rw-r--r-- 1 u0 u0   327 Jul 30 18:34 sitemap.xml
drwxr-xr-x 2 u0 u0  4096 Jul 27 11:42 thumbnails
drwxr-xr-x 4 u0 u0  4096 Jul 30 18:34 zh-hans

Please help. Thanks in adv.

Try this,

...
{{- $ret = resources.GetMatch $v.Source -}}
{{- if $ret -}}
        {{- if $v.Resize -}}
                {{- $ret = $original.Resize $data.Dimension -}}
        {{- end -}}
        
        {{- $ret_new := $ret.Content | resources.FromString $data.Filename -}}
        {{- $data = merge $data (dict "URL" $ret_new.Permalink) -}}
        ...
{{- end -}}
...
1 Like

Thanks! It works flawlessly with build command: hugo --cacheDir "..." --ignoreCache --cleanDestinationDir --forceSyncStatic --minify --destination "..."

UPDATE:

I refactored it as follows, it works as well:

...
{{- $ret = resources.GetMatch $v.Source -}}
{{- if $ret -}}
        {{- if $v.Resize -}}
                {{- $ret = $original.Resize $data.Dimension -}}
        {{- end -}}
        
        {{- $ret = resources.FromString $data.Filename $ret.Content -}}
        {{- $data = merge $data (dict "URL" $ret_new.Permalink) -}}
        ...
{{- end -}}
...
1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.