@tdelmas, it should possible to do this automatically in the build command itself with something similar to the following:
hugo -b "$URL"
There are also some examples here in the Hugo docs for deploy previews, to “bake in” the deploy preview URL like so (this goes in netlify.toml):
[context.deploy-preview]
command = "hugo --gc --minify --buildFuture -b $DEPLOY_PRIME_URL"
This uses a different environment variable $DEPLOY_PRIME_URL which is specific to the deploy previews.
Using these methods, it should be possible to make the URLs always specific to where they are deployed.