theNewDynamic / gohugo-theme-ananke

Ananke: A theme for Hugo Sites
https://gohugo-ananke-theme-demo.netlify.com/
MIT License
1.1k stars 1.13k forks source link

Support Hugo's built in build environment feature #574

Closed jhenstridge closed 1 year ago

jhenstridge commented 1 year ago

Hugo has built-in support for multiple build environments that is exposed to templates via the hugo.Environment and hugo.IsProduction variables. This is controlled via the --environment command line argument with the HUGO_ENV environment variable as a fallback.

Ananke has some support for build environments, but it does it by checking the HUGO_ENV environment variable directly:

https://github.com/theNewDynamic/gohugo-theme-ananke/blob/5a8b531a7ce2f22eaa452ebab8325040982c9275/layouts/_default/baseof.html#L12

This means Ananke's view of the build environment will match Hugo's if it was set by the environment variable but not if it was set via the command line.

It looks like this could be simplified to just using hugo.IsProduction. This would result in a change in behaviour when no environment is set at all. According to the docs, here are the results:

Default environments are development with hugo server and production with hugo.

regisphilibert commented 1 year ago

Exactly, if we do this, then Ananke would treat any website with the default hugo command line as a production site. Any deploy preview etc... would be considered production.

It's an easy code change, but a difficult effort in communication to make sure everyone gets the memo.

Juanpam commented 10 months ago

@regisphilibert I found this today! I'd say it would be worth it to document it at least as this theme is used in the getting started tutorial from Hugo. It can be confusing since it kinds of conflicts with what's specified in the docs.

BTW, I got the memo lol