Straightforward way to disallow indexing of a few pages

Hi, I am using hugo and Academic theme. Thanks for the great software! I am not a pro web designer - I am a doctor who runs a small informational site for trainees.

I understand there are two types of indexing - by search engines and by the site itself (tags, taxonomies, etc). I want to be able to make one or two pages that are accessible only by a link that I share. Password protection is not essential, I just do not want the pages to be accessible via (google) search or through hugo internal indexing mechanisms from site front page or blog index. What would be the simplest mechanism to achieve both objectives?

Many thanks,

Robert

You can add a new frontmatter variable:

---
index: false
---

and in your templates, you can add the following:

  1. To disable search engines, in the <head> of the document, you can add:
{{- if not .Params.Index -}}
  <meta name = "robots" content = "noindex">
{{- end -}}
  1. To disable the page from lists, you’ll have to find the file responsible for generating the list pages and it might have something like {{- range .Pages -}} or {[- range .Paginator.Pages -}} (or something along the similar lines). There you can add this:
{{- range (statement from above) -}}
  {{- if not .Params.Index -}}
    <!-- code responsible to generate the links to posts -->
  {{- end -}}
{{- end -}}

Basically, you just need to wrap the code in the if statement. So, on any page on which you add index: false in the frontmatter, the SEO and post links would be disabled.

1 Like

This is excellent. Over the weekend I will try this out in a detailed way and ask for more help if I get stuck. I will also update which bit of Academic template needs updating.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.