TL;DR
- introduce a new setting to your front-matter “index”
- when set to true, the page should be indexed
- use it in head template at
layouts/partials/head/head.htmlto generate the according meta robots tag
{{- if .Params.index }}
<meta name = "robots" content = "index">
{{- else }}
<meta name = "robots" content = "noindex">
{{- end }}
- if you are using a theme, copy their
head.htmland adjust it accordingly. Hugo will use your template when building for prod but a head.html partial usually contains more than just the meta robots tag
Warning
Keep in mind: This will lead to all content not being indexed and only content being indexed where you specify “index = true” in your front matter. This also means that content automatically generated by Hugo (i.e. content you do not manually curate a template for) will not be indexed.