From 7ccd084ad71bbb22af9f89c533633e63bb26a4b2 Mon Sep 17 00:00:00 2001 From: Joe Mooring Date: Mon, 16 Jun 2025 22:27:21 -0700 Subject: [PATCH] search: Use front matter parameter to control search indexing Closes #3108 --- content/en/contribute/documentation.md | 45 +-- content/en/quick-reference/emojis.md | 2 + content/en/quick-reference/glossary/_index.md | 1 + hugo.toml | 270 +++++++++--------- layouts/_partials/layouts/related.html | 2 +- layouts/baseof.html | 9 +- 6 files changed, 174 insertions(+), 155 deletions(-) diff --git a/content/en/contribute/documentation.md b/content/en/contribute/documentation.md index 1bede2200..6e9b5b8bb 100644 --- a/content/en/contribute/documentation.md +++ b/content/en/contribute/documentation.md @@ -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 diff --git a/content/en/quick-reference/emojis.md b/content/en/quick-reference/emojis.md index 15c2e60e6..75f269730 100644 --- a/content/en/quick-reference/emojis.md +++ b/content/en/quick-reference/emojis.md @@ -3,6 +3,8 @@ title: Emojis description: Include emoji shortcodes in your Markdown or templates. categories: [] keywords: [] +params: + searchable: false --- ## Attribution diff --git a/content/en/quick-reference/glossary/_index.md b/content/en/quick-reference/glossary/_index.md index 42894c4da..8940fd73b 100644 --- a/content/en/quick-reference/glossary/_index.md +++ b/content/en/quick-reference/glossary/_index.md @@ -13,6 +13,7 @@ cascade: layout: single params: hide_in_this_section: true + searchable: true aliases: [/getting-started/glossary/] --- diff --git a/hugo.toml b/hugo.toml index bb3a570c4..807f14b87 100644 --- a/hugo.toml +++ b/hugo.toml @@ -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 world’s 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 world’s 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 diff --git a/layouts/_partials/layouts/related.html b/layouts/_partials/layouts/related.html index 0245ba771..dac5b8d5b 100644 --- a/layouts/_partials/layouts/related.html +++ b/layouts/_partials/layouts/related.html @@ -14,7 +14,7 @@ {{ or .Params.altTitle .Title }}{{ or .Params.alt_title .Title }} {{- end }} diff --git a/layouts/baseof.html b/layouts/baseof.html index d2de68c83..c5df69a92 100644 --- a/layouts/baseof.html +++ b/layouts/baseof.html @@ -32,8 +32,13 @@ {{ end }} {{ partial "layouts/head/head.html" . }} - + + {{ $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 }} + + {{ partial "layouts/hooks/body-start.html" . }} {{/* Layout. */}} {{ block "header" . }}