hextra icon indicating copy to clipboard operation
hextra copied to clipboard

Overriding index directive for certain page

Open MattDodsonEnglish opened this issue 10 months ago • 3 comments

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

MattDodsonEnglish avatar Mar 10 '25 22:03 MattDodsonEnglish

I recommend just overriding the head.html partial

imfing avatar Mar 10 '25 23:03 imfing

I recommend just overriding the head.html partial

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 avatar Mar 17 '25 21:03 MattDodsonEnglish

@MattDodsonEnglish I'm open to add a flag to it as long as it has reasonable defaults + properly documented

imfing avatar Mar 18 '25 20:03 imfing

this has been done in https://github.com/imfing/hextra/pull/671

imfing avatar Jun 01 '25 16:06 imfing