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
This commit is contained in:
Matt Dodson 2025-05-17 18:35:26 -03:00 committed by GitHub
parent f194bc64e4
commit 128235e7e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 3 deletions

View File

@ -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.

View File

@ -1,7 +1,8 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
{{ if hugo.IsProduction -}}
{{- $noindex := .Params.noindex | default false -}}
{{ if and (hugo.IsProduction) (not $noindex) -}}
<meta name="robots" content="index, follow" />
{{ else -}}
<meta name="robots" content="noindex, nofollow" />