HUGO

Shortcodes not behaving the same in deployed site as in local build

Hello everyone,

I noticed that my shortcodes don’t behave the same in the deployed site (hosted with GitHub Pages, deployed with GitHub Actions as described in the official documentation) as in a local build (built locally with hugo server or hugo server -D, localhost).

Before I come to the point, I also wanted to mention that I noticed that, after running the hugo command, all the website files get stored in a folder called docs, not in the public folder. It didn’t prevent me from deploying my site, since I simply changed the publish_dir to docs. I hope that’s not something horribly bad or an unintended behaviour. Just wanted to mention that first. I am using Hugo v.0.83.1.

Now regarding my actual problem. In my locally built site, the shortcode behaves as expected. It’s a simple shortcode formatting the content of it. The only problem is, that even though I actually added a space between the text and the declaration of the shortcode (see example below), it doesn’t add a space in the deployed site on GitHub Pages, whereas it behaves as expected in a locally built site.

Let me show an example.
This is the Markdown content:

Apart from the {{<link `path` `_blank`>}}official API reference{{</link>}}

And this is the shortcode (simplified):

{{ $p0 := .Get 0 }}
{{ $p1 := .Get 1 }}
{{ $inner := .Inner }}
<a href="{{ $p0 }}" target="{{ $p1 }}" class="shortcode-link">{{$inner}}</a>

(I even tried to add a space inside the shortcode, didn’t help either)
This is how it looks like in the locally built site:
image

This is how it looks like in the deployed site:
image

That happens with two shortcodes, that are supposed to format inline text inside a block of text and no attempt to fix this worked. Whether it’s adding another space inside the Markdown file or adding a space inside the shortcode. None of these attempts turned out to be helpful.

Thank you already in advance.

  • Are you 100% that is the version both locally and on GitLab?
  • Also, do you run with the --minify flag on GitLab?
  1. Well, no, it was set to ‘latest’ and that would be v0.85.0. Changing it to ‘0.83.1’ doesn’t seem to change anything though.
  2. Yes:
run: hugo --minify

Both locally and on GitLab?

No, indeed not. Running it locally with --minify yields the same results as the deployed version. Seems like this was the reason.
Do I have to run it with the --minify flag (on GitLab) or is there a workaround with that?

I assume you mean the other way around, but yes.

This sounds like a bug in the built-in minifier in Hugo. Could you raise an issue on GitHub about this?

Sure, I will repeat the same question with the additional information from the replies in this conversation.

Thank you for your help, I guess I’ll wait for a new release in the future, since this issue doesn’t have to be urgently fixed.

I am unable to reproduce the problem. Make sure you include a minimal reproducible example when you create the GitHub issue.

Reference: https://github.com/gohugoio/hugo/issues/8748