Preventing image page resources from being published

I (try to) have a multilingual Hugo site, “de” being the default language and these pages being translated into English. index.html and index.en.html are always in the same page bundle, together with the JPG images used in both language versions. The de and en pages always use the same images.

My image render hook and other image processing templates convert the JPG to WebP in various sizes, and the generated HTML never references the JPG images. I checked that.

I also checked that neither Publish, Permalink or RelPermalink are called on any of the image resources, i.e., the JPG files.

In hugo.toml, publishResources is set to false.
However, I still have JPG files in the directories under public. And yes, I did clean out public before running hugo server.

Since these files just sit there and eat space uselessly, I’d love to prevent Hugo from copying them from the page bundles to the public directories, but I’m out of my wits here.

Is there anything else I should check for, or is there a way to see when the JPGs get copied?

Can you provide details?

Like this?

[build]
  writeStats = true
  publishResources = false

When I look closer at the documentation, I’m wondering if I do have to set that on all page bundles separately.

There isn’t a publishResources parameter under the site config’s build key.

You’re looking for the build page param.

https://gohugo.io/content-management/build-options/

Apparently. I now changed my _index.md in the branch directory to

---
title: "Post"
date: 2021-03-02T20:22:11+01:00
build:
  publishResources: false
cascade:
- build:
  publishResources: false
---

That’s what I understood from the example at Build options
But the JPGs still get published.

This works as expected:

git clone --single-branch -b hugo-forum-topic-55883 https://github.com/jmooring/hugo-testing hugo-forum-topic-55883
cd hugo-forum-topic-55883
rm -rf public && hugo && tree public

So there must be something different about my (perhaps) simplified example.

You’re YAML structure is incorrect (indentation problem).

Change this:

cascade:
- build:
  publishResources: false

To this:

cascade:
- build:
    publishResources: false

I changed the indentation, but that doesn’t change anything. And I forgot to mention that I have this in my hugo.toml

# EN content
[[module.mounts]]
source = 'content'
target = 'content'
lang = 'en'
# DE content
[[module.mounts]]
source = 'content'
target = 'content'
lang = 'de'

No idea if the issue is related to that setting, but I can’t change it because otherwise the site will not build at all due to not everything being translated yet. So… I’ll put the issue to rest. A simple find public -name ".jpg" -exec rm {} \; after running hugo will clear everything up, too.

Did you clear the public directory before testing again?

I added your unexpected/unusual module mounts and everything works as expected. Pull changes on the example site or clone again:

git clone --single-branch -b hugo-forum-topic-55883 https://github.com/jmooring/hugo-testing hugo-forum-topic-55883
cd hugo-forum-topic-55883
rm -rf public && hugo && tree public

Thanks for your efforts!

Yep. No change.

I did, and your sample works as expected. Since the setup is now identical, I suppose one of my templates is still doing something to the JPG files that causes them to be published.
I’ll lay that issue to rest. Thanks again for your help!

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