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/]
---

View File

@ -27,13 +27,23 @@ disableAliases = true
dir = ':cacheDir/:project'
maxAge = "1h"
[cascade]
[[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
@ -140,7 +150,7 @@ disableAliases = true
ID = 'G-MBZGKNMDWC'
[taxonomies]
category = 'categories'
category = 'categories'
######## GLOBAL ITEMS TO BE SHARED WITH THE HUGO SITES ########
[menus]

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" . }}