search: Use front matter parameter to control search indexing

Closes #3108
This commit is contained in:
Joe Mooring 2025-06-16 22:27:21 -07:00
parent b4f90e39d4
commit 7ccd084ad7
6 changed files with 174 additions and 155 deletions

View File

@ -152,26 +152,27 @@ This example demonstrates the minimum required front matter fields.
If quotation marks are required, prefer single quotes to double quotes when possible.
Seq|Field|Description|Required
--:|:--|:--|:--
1|`title`|The page title|:heavy_check_mark:|
2|`linkTitle`|A short version of the page title||
3|`description`|A complete sentence describing the page|:heavy_check_mark:|
4|`categories`|An array of terms in the categories taxonomy|:heavy_check_mark: [^1]|
5|`keywords`|An array of keywords used to identify related content|:heavy_check_mark: [^1]|
6|`publishDate`|Applicable to news items: the publication date||
7|`params.altTitle`|An alternate title: used in the "see also" panel if provided||
8|`params.functions_and_methods.aliases`|Applicable to function and method pages: an array of alias names||
9|`params.functions_and_methods.returnType`|Applicable to function and method pages: the data type returned||
10|`params.functions_and_methods.signatures`|Applicable to function and method pages: an array of signatures||
11|`params.hide_in_this_section`|Whether to hide the "in this section" panel||
12|`params.minversion`|Applicable to the quick start page: the minimum Hugo version required||
13|`params.permalink`|Reserved for use by the news content adapter||
14|`params.reference (used in glossary term)`|Applicable to glossary entries: a URL for additional information||
15|`params.show_publish_date`|Whether to show the `publishDate` when rendering the page||
16|`weight`|The page weight||
17|`aliases`|Previous URLs used to access this page||
18|`expirydate`|The expiration date||
Field|Description|Required
:--|:--|:--
`title`|The page title|:heavy_check_mark:|
`linkTitle`|A short version of the page title||
`description`|A complete sentence describing the page|:heavy_check_mark:|
`categories`|An array of terms in the categories taxonomy|:heavy_check_mark: [^1]|
`keywords`|An array of keywords used to identify related content|:heavy_check_mark: [^1]|
`publishDate`|Applicable to news items: the publication date||
`params.alt_title`|An alternate title: used in the "see also" panel if provided||
`params.functions_and_methods.aliases`|Applicable to function and method pages: an array of alias names||
`params.functions_and_methods.returnType`|Applicable to function and method pages: the data type returned||
`params.functions_and_methods.signatures`|Applicable to function and method pages: an array of signatures||
`params.hide_in_this_section`|Whether to hide the "in this section" panel||
`params.minversion`|Applicable to the quick start page: the minimum Hugo version required||
`params.permalink`|Reserved for use by the news content adapter||
`params.reference (used in glossary term)`|Applicable to glossary entries: a URL for additional information||
`params.searchable`|Whether to add the content of this page to the search index. The default value is cascaded down from the site configuration; `true` if the page kind is `page`, and `false` if the page kind is one of `home`, `section`, `taxonomy`, or `term`. Add this field to override the default value.||
`params.show_publish_date`|Whether to show the `publishDate` when rendering the page||
`weight`|The page weight||
`aliases`|Previous URLs used to access this page||
`expirydate`|The expiration date||
[^1]: The field is required, but its data is not.
@ -185,13 +186,13 @@ If the title in the "See also" sidebar is ambiguous or the same as another page,
title = "Long descriptive title"
linkTitle = "Short title"
[params]
altTitle = "Whatever you want"
alt_title = "Whatever you want"
{{< /code-toggle >}}
Use of the alternate title is limited to the "See also" sidebar.
> [!note]
> Think carefully before setting the `altTitle`. Use it only when absolutely necessary.
> Think carefully before setting the `alt_title`. Use it only when absolutely necessary.
## Code examples

View File

@ -3,6 +3,8 @@ title: Emojis
description: Include emoji shortcodes in your Markdown or templates.
categories: []
keywords: []
params:
searchable: false
---
## Attribution

View File

@ -13,6 +13,7 @@ cascade:
layout: single
params:
hide_in_this_section: true
searchable: true
aliases: [/getting-started/glossary/]
---

270
hugo.toml
View File

@ -9,165 +9,175 @@ title = "Hugo"
disableAliases = true
[build]
[build.buildStats]
disableIDs = true
enable = true
[[build.cachebusters]]
source = "assets/notwatching/hugo_stats\\.json"
target = "css"
[[build.cachebusters]]
source = "(postcss|tailwind)\\.config\\.js"
target = "css"
[build.buildStats]
disableIDs = true
enable = true
[[build.cachebusters]]
source = "assets/notwatching/hugo_stats\\.json"
target = "css"
[[build.cachebusters]]
source = "(postcss|tailwind)\\.config\\.js"
target = "css"
[caches]
[caches.images]
dir = ":cacheDir/images"
maxAge = "1440h"
[caches.getresource]
dir = ':cacheDir/:project'
maxAge = "1h"
[caches.images]
dir = ":cacheDir/images"
maxAge = "1440h"
[caches.getresource]
dir = ':cacheDir/:project'
maxAge = "1h"
[cascade]
[cascade.params]
hide_in_this_section = true
show_publish_date = true
[cascade.target]
kind = 'page'
path = '{/news/**}'
[[cascade]]
[cascade.params]
hide_in_this_section = true
show_publish_date = true
[cascade.target]
kind = 'page'
path = '{/news/**}'
[[cascade]]
[cascade.params]
searchable = true
[cascade.target]
kind = 'page'
[[cascade]]
[cascade.params]
searchable = false
[cascade.target]
kind = '{home,section,taxonomy,term}'
[frontmatter]
date = ['date'] # do not add publishdate; it will affect page sorting
expiryDate = ['expirydate']
lastmod = [':git', 'lastmod', 'publishdate', 'date']
publishDate = ['publishdate', 'date']
date = ['date'] # do not add publishdate; it will affect page sorting
expiryDate = ['expirydate']
lastmod = [':git', 'lastmod', 'publishdate', 'date']
publishDate = ['publishdate', 'date']
[languages]
[languages.en]
languageCode = "en-US"
languageName = "English"
weight = 1
[languages.en]
languageCode = "en-US"
languageName = "English"
weight = 1
[markup]
[markup.goldmark]
[markup.goldmark.extensions]
[markup.goldmark.extensions.typographer]
disable = false
[markup.goldmark.extensions.passthrough]
enable = true
[markup.goldmark.extensions.passthrough.delimiters]
block = [['\[', '\]'], ['$$', '$$']]
inline = [['\(', '\)']]
[markup.goldmark.parser]
autoDefinitionTermID = true
[markup.goldmark.parser.attribute]
block = true
[markup.highlight]
lineNumbersInTable = false
noClasses = false
style = 'solarized-dark'
wrapperClass = 'highlight not-prose'
[markup.goldmark]
[markup.goldmark.extensions]
[markup.goldmark.extensions.typographer]
disable = false
[markup.goldmark.extensions.passthrough]
enable = true
[markup.goldmark.extensions.passthrough.delimiters]
block = [['\[', '\]'], ['$$', '$$']]
inline = [['\(', '\)']]
[markup.goldmark.parser]
autoDefinitionTermID = true
[markup.goldmark.parser.attribute]
block = true
[markup.highlight]
lineNumbersInTable = false
noClasses = false
style = 'solarized-dark'
wrapperClass = 'highlight not-prose'
[mediaTypes]
[mediaTypes."text/netlify"]
delimiter = ""
[mediaTypes."text/netlify"]
delimiter = ""
[module]
[module.hugoVersion]
min = "0.144.0"
[[module.mounts]]
source = "assets"
target = "assets"
[[module.mounts]]
lang = 'en'
source = 'content/en'
target = 'content'
[[module.mounts]]
disableWatch = true
source = "hugo_stats.json"
target = "assets/notwatching/hugo_stats.json"
[module.hugoVersion]
min = "0.144.0"
[[module.mounts]]
source = "assets"
target = "assets"
[[module.mounts]]
lang = 'en'
source = 'content/en'
target = 'content'
[[module.mounts]]
disableWatch = true
source = "hugo_stats.json"
target = "assets/notwatching/hugo_stats.json"
[outputFormats]
[outputFormats.redir]
baseName = "_redirects"
isPlainText = true
mediatype = "text/netlify"
[outputFormats.headers]
baseName = "_headers"
isPlainText = true
mediatype = "text/netlify"
notAlternative = true
[outputFormats.redir]
baseName = "_redirects"
isPlainText = true
mediatype = "text/netlify"
[outputFormats.headers]
baseName = "_headers"
isPlainText = true
mediatype = "text/netlify"
notAlternative = true
[outputs]
home = ["html", "rss", "redir", "headers"]
page = ["html"]
section = ["html"]
taxonomy = ["html"]
term = ["html"]
home = ["html", "rss", "redir", "headers"]
page = ["html"]
section = ["html"]
taxonomy = ["html"]
term = ["html"]
[params]
description = "The worlds fastest framework for building websites"
ghrepo = "https://github.com/gohugoio/hugoDocs/"
[params.render_hooks.link]
errorLevel = 'warning' # ignore (default), warning, or error (fails the build)
[params.social.mastodon]
url = "https://fosstodon.org/@gohugoio"
description = "The worlds fastest framework for building websites"
ghrepo = "https://github.com/gohugoio/hugoDocs/"
[params.render_hooks.link]
errorLevel = 'warning' # ignore (default), warning, or error (fails the build)
[params.social.mastodon]
url = "https://fosstodon.org/@gohugoio"
[related]
includeNewer = true
threshold = 80
toLower = true
[[related.indices]]
name = 'keywords'
weight = 1
includeNewer = true
threshold = 80
toLower = true
[[related.indices]]
name = 'keywords'
weight = 1
[security]
[security.funcs]
getenv = ['^HUGO_', '^REPOSITORY_URL$', '^BRANCH$']
[security.funcs]
getenv = ['^HUGO_', '^REPOSITORY_URL$', '^BRANCH$']
[server]
[[server.headers]]
for = "/*"
[server.headers.values]
X-Frame-Options = "DENY"
X-XSS-Protection = "1; mode=block"
X-Content-Type-Options = "nosniff"
Referrer-Policy = "no-referrer"
[[server.headers]]
for = "/**.{css,js}"
[[server.headers]]
for = "/*"
[server.headers.values]
X-Frame-Options = "DENY"
X-XSS-Protection = "1; mode=block"
X-Content-Type-Options = "nosniff"
Referrer-Policy = "no-referrer"
[[server.headers]]
for = "/**.{css,js}"
[services]
[services.googleAnalytics]
ID = 'G-MBZGKNMDWC'
[services.googleAnalytics]
ID = 'G-MBZGKNMDWC'
[taxonomies]
category = 'categories'
category = 'categories'
######## GLOBAL ITEMS TO BE SHARED WITH THE HUGO SITES ########
[menus]
[[menus.global]]
identifier = 'news'
name = 'News'
pageRef = '/news/'
weight = 1
[[menus.global]]
identifier = 'docs'
name = 'Docs'
url = '/documentation/'
weight = 5
[[menus.global]]
identifier = 'themes'
name = 'Themes'
url = 'https://themes.gohugo.io/'
weight = 10
[[menus.global]]
identifier = 'community'
name = 'Community'
post = 'external'
url = 'https://discourse.gohugo.io/'
weight = 150
[[menus.global]]
identifier = 'github'
name = 'GitHub'
post = 'external'
url = 'https://github.com/gohugoio/hugo'
weight = 200
[[menus.global]]
identifier = 'news'
name = 'News'
pageRef = '/news/'
weight = 1
[[menus.global]]
identifier = 'docs'
name = 'Docs'
url = '/documentation/'
weight = 5
[[menus.global]]
identifier = 'themes'
name = 'Themes'
url = 'https://themes.gohugo.io/'
weight = 10
[[menus.global]]
identifier = 'community'
name = 'Community'
post = 'external'
url = 'https://discourse.gohugo.io/'
weight = 150
[[menus.global]]
identifier = 'github'
name = 'GitHub'
post = 'external'
url = 'https://github.com/gohugoio/hugo'
weight = 200

View File

@ -14,7 +14,7 @@
<a
class="text-sm text-blue-600 hover:text-blue-500 dark:text-blue-500 dark:hover:text-blue-400"
href="{{ .RelPermalink }}"
>{{ or .Params.altTitle .Title }}</a
>{{ or .Params.alt_title .Title }}</a
>
</li>
{{- end }}

View File

@ -32,8 +32,13 @@
{{ end }}
{{ partial "layouts/head/head.html" . }}
</head>
<body
class="flex flex-col min-h-full bg-white dark:bg-blue-950 kind-{{ .Kind }}">
{{ $bodyClass := printf "flex flex-col min-h-full bg-white dark:bg-blue-950 kind-%s" .Kind }}
{{ if .Params.searchable }}
{{ $bodyClass = printf "%s searchable" $bodyClass }}
{{ end }}
<body class="{{ $bodyClass }}">
{{ partial "layouts/hooks/body-start.html" . }}
{{/* Layout. */}}
{{ block "header" . }}