From 128235e7e2d4f34a8a427f72e749a149c5d30851 Mon Sep 17 00:00:00 2001 From: Matt Dodson <47385188+MattDodsonEnglish@users.noreply.github.com> Date: Sat, 17 May 2025 18:35:26 -0300 Subject: [PATCH] feat(seo): add page param to block Google indexing Add a `noindex` param to page front matter to block Google indexing for specific pages or directories. This is useful for avoiding duplicate content in search results or preventing indexing of pages that shouldn't appear in search engines. - Adjust `head.html` for optional `noindex` param (default: false) - Document usage in `configuration.md` and clarify Flexsearch section --- .../content/docs/guide/configuration.md | 21 +++++++++++++++++-- layouts/partials/head.html | 3 ++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/exampleSite/content/docs/guide/configuration.md b/exampleSite/content/docs/guide/configuration.md index 7b41273..32d7b77 100644 --- a/exampleSite/content/docs/guide/configuration.md +++ b/exampleSite/content/docs/guide/configuration.md @@ -243,7 +243,7 @@ There are three available options: `full`, `wide`, and `normal`. By default, the Similarly, the width of the navbar and footer can be customized by the `params.navbar.width` and `params.footer.width` parameters. -### Search Index +### FlexSearch Index Full-text search powered by [FlexSearch](https://github.com/nextapps-de/flexsearch) is enabled by default. To customize the search index, set the `params.search.flexsearch.index` parameter in the config file: @@ -284,7 +284,7 @@ Options for [`flexsearch.tokenize`](https://github.com/nextapps-de/flexsearch/#t - `reverse` - incrementally index words in both directions - `full` - index every possible combination -To exclude a page from the search index, set the `excludeSearch: true` in the front matter of the page: +To exclude a page from the FlexSearch search index, set the `excludeSearch: true` in the front matter of the page: ```yaml {filename="content/docs/guide/configuration.md"} --- @@ -302,3 +302,20 @@ services: googleAnalytics: ID: G-MEASUREMENT_ID ``` + +### Google Search Index + +To [block Google Search](https://developers.google.com/search/docs/crawling-indexing/block-indexing) from indexing a page, set `noindex` to true in your page frontmatter: + +```yaml +title: Configuration (archive version) +params: + noindex: true +``` + +To exclude an entire directory, use the [`cascade`](https://gohugo.io/configuration/cascade/) key in the parent `_index.md` file. + +> [!NOTE] +> To block search crawlers, you can make a [`robots.txt` template](https://gohugo.io/templates/robots/). +> However, `robots.txt` instructions do not necessarily keep a page out of Google search results. + diff --git a/layouts/partials/head.html b/layouts/partials/head.html index a1f4954..25ab330 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -1,7 +1,8 @@ - {{ if hugo.IsProduction -}} + {{- $noindex := .Params.noindex | default false -}} + {{ if and (hugo.IsProduction) (not $noindex) -}} {{ else -}}