Checking ENV variable prevents site from being indexed by Google on AWS

Hi,

I’m using a template that includes the following code in the header partial:

{{ if eq (getenv “HUGO_ENV”) “production” }}
<META NAME=“ROBOTS” CONTENT=“INDEX, FOLLOW”>
{{ else }}
<META NAME=“ROBOTS” CONTENT=“NOINDEX, NOFOLLOW”>
{{ end }}

The template I’m using is Docsy, but I understand this applies to other templates as well. However, this code will prevent Google from indexing a site unless the ENV env variable is set to PRODUCTION. I’m deploying my site to an AWS bucket and so far as I know the env variable cannot be read (https://stackoverflow.com/questions/36226645/configuring-environment-variables-for-static-web-site-on-aws-s3). So I ended up commenting out those lines of code.

Does anyone have experience deploying to AWS and handling the above?

Thanks

Arnon

The above can be rewritten to:

{{ if eq hugo.Environment “production” }}
<META NAME=“ROBOTS” CONTENT=“INDEX, FOLLOW”>
{{ else }}
<META NAME=“ROBOTS” CONTENT=“NOINDEX, NOFOLLOW”>
{{ end }}

Which should be more portable.

1 Like