Build two versions of the same project

Hi Everyone!

I’ve got a Hugo documentation project and I would like to build two versions. An “offline” one that people can download and read on their machine, and a regular online one.

The difference between the two would be in the homepage layout and the header. The offline version has a little paragraph about it being the offline version and direct users to the latest version online. It would also say “offline” in the header. What is the best way to go about this?

To complicate things, this project already uses an environment to build only specific topics when that environment is used. Would the solution to the offline/online split be something similar?

Thank you very much for your help!

Either build with a different environment (hugo --environment) or inject an env param (see os.Getenv).

As to env vars, I would recommend injecting it into site.Params, e.g. HUGO_PARAMS_FOO=bar.

Prior to v0.84.0 you could not inject HUGO_PARAMS_A_B=foo unless the [params.a] table was already defined in site configuration. Thanks for fixing this!

Thank you, I’ll look into this!

Thank you. Would you mind giving a bit more info on how this works? Where do I add this? Do I need to add anything to the config?

You build your site:

HUGO_PARAMS_FOO="bar" hugo

Then access the parameter from within a template:

{{ if eq "bar" }}
{{ end }}

Thanks! That’s what I tried but it didn’t work and now I realised I have a very old version of Hugo installed (v0.67), so that’s probably why. I’ll upgrade and see if it works!

So. I upgraded to v0.90 and I still get “‘HUGO_PARAMS_FOO’ is not recognized as an internal or external command, operable program or batch file.” Not sure what I’m missing

On Windows, you set environment variables with the set command.

set HUGO_PARAMS_FOO=bar && hugo

Ah, thank you. Sorry, I’m not very technical. So here’s the bit in my partial:

{{ if eq “yes” site.Params.offline }}

This documentation is provided offline, so you can access it locally. Any updates made to the documentation since this release are available online.

{{ end }}

And then I build with:

set HUGO_PARAMS_OFFLINE=yes && hugo

But the paragraph doesn’t get added. However, if I actually add a parameter within my config file and just build as normal, that works. So my partial seems to be fine.

What am I missing?

What version?


I love Windows.

When you do this:

set HUGO_PARAMS_FOO=bar && hugo

Windows sets the value of HUGO_PARAMS_FOO to "bar " (see the extra space?)

When you do this:


Windows sets the value of HUGO_PARAMS_FOO to “bar” (no extra space)

1 Like

Hah, I would never have figured that out. Thanks so much for your help and patience, it works now!

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