Overriding index directive for certain page
Feature Description Add a frontmatter parameter that provides a way to add a noindex tag.
Problem/Solution
It's possible to add custom headers using the partials/custom/head-end.html.
However, using this to add a nonindex tag would conflict with the main head.html partial:
{{ if hugo.IsProduction -}}
<meta name="robots" content="index, follow" />
Alternatives Considered
- Use Robots.txt, though as I understand some pages might get indexed if they are linked
- accept the conflict
- overwrite the current head partial
Additional Context
Duplicate content for versions
I recommend just overriding the head.html partial
I recommend just overriding the
head.htmlpartial
That's what we're currently doing:
{{ if and (hugo.IsProduction) (not .Params.noindex) -}}
<meta name="robots" content="index, follow" />
{{ else -}}
<meta name="robots" content="noindex, nofollow" />
{{ end -}}
Using cascade to specify noindex: true directories.
The downside is that we have to manually add any changes that the Hextra theme makes to head.html later. Of course, since it's a feature that I need, I'd prefer that it were a part of the theme itself. But I appreciate the choice to not indiscriminately add features.
If there's no interest in adding, please feel free to close the issue.
@MattDodsonEnglish I'm open to add a flag to it as long as it has reasonable defaults + properly documented
this has been done in https://github.com/imfing/hextra/pull/671