Is there a way to disable/remove portions of my page while testing with hugo server
?
While developing, I want to disable my site’s Google analytics and ads in my html template pages.
I was hoping this might be possible with some sort of conditional code you can add to the templates.
Too nice! Thank you very much.
Is there a way to differentiate based on the fact that you are running hugo server
instead of just the -D
flag?
In other words, I want to view the site with hugo server
, just as it will look (without drafts) in the live environment, but I still want to disable analytics, ads etc.
bep
March 7, 2018, 10:48am
5
No, but the common way of doing this is to check a user defined environment variable:
{{ if eq (getenv "env") "prod" }}
// include google analytics
{{ end }}
You need to then do:
HUGO_ENV=prod hugo
When you publish your site.
Thank you for the suggestion.
So this requires a change to a file somewhere. Problem for me is, I might forget and then publish the site without remembering to make that change…
Do you think this is worth a feature request? Some way to identify when the site is being shown under hugo server
? Does it sound feasible?
bep
March 7, 2018, 11:02am
7
mydoghasworms:
Does it sound feasible?
Yes, it is easy to add. Please create a new GitHub issue.
We’ve had a discussion about adding an IsDev
flag or something, and that is harder to decide. But the IsServer
is easy to answer.