Issues with Permanent links and metadata partials in Hugo

I understand that this is only partly an issue of Netlify, though it should be at least somehow made clear in the documentation that core functionality of Hugo does not work as intended.

More specifically, Hugo has several built-in partials / templates, used to generate the respective meta tags for OGraph, Twitter etc. These of course require an absolute URL (.Permalink in Hugo terminology) for the simple purpose that parsers by Facebook and Twitter do not understand relative URLs. Of course the same issue applies in the generation of share links (unless one resorts to JavaScript).

Is there a way to work around this?

The following internal partials are impacted:

{{ template "_internal/opengraph.html" . }}
{{ template "_internal/twitter_cards.html" . }}
{{ template "_internal/schema.html" . }}

Example site where the metadata URLs are wrong:

Heya @Heracles ! I only see one og property in that page and it seems to have a full URL:

<meta property=og:url content=>

I don’t see that you even have prerendering enabled, which is the usual “get everything in shape for social sharing” first steps: and see also [Common Issue] Understanding and debugging prerendering for more details about that implementation.

Could you let me know a bit more detail about what you’re seeing that isn’t working as expected?

Hi @fool, thanks for taking the time to look into this. It doesn’t seem prerendering fits this case; isn’t it intended for single-page sites?

I’d previously disabled the share links (which have a full URL) but you can see them in effect here: where the netlify URl is exposed.

I have set HUGO_BASEURL but doesn’t seem to have any effect.

It looks like the build command for this site is this:

hugo --gc --minify -b $DEPLOY_PRIME_URL

If you are setting the base URL in an environment variable (and I show that you are), it might help to use that instead in the build command like so:

hugo --gc --minify -b "$HUGO_BASEURL"

Would you please test that and let us know if it resolves the issue or not?

1 Like

@luke That did it, thank you! I followed the wizard and never realized changing the build command would do it.