From 1a9dc69bd0c2f425673ad3ca088b5b8cd947f004 Mon Sep 17 00:00:00 2001 From: David Karlsson <35727626+dvdksn@users.noreply.github.com> Date: Fri, 17 Jan 2025 17:06:00 +0100 Subject: [PATCH] chore: tidy templates, add comments Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com> --- layouts/_default/search.html | 8 ++++++++ layouts/index.metadata.json | 2 +- layouts/index.redirects.json | 22 ++++++++++++++++++++++ layouts/index.robots.txt | 6 ++++++ layouts/partials/github-links.html | 5 +++++ layouts/partials/head.html | 11 ----------- layouts/partials/meta.html | 9 ++++----- layouts/partials/pagemeta.html | 7 +++++++ layouts/partials/search-bar.html | 8 ++++++++ layouts/partials/sidebar/guides.html | 8 ++++++++ layouts/partials/sidebar/mainnav.html | 6 ++++++ layouts/partials/sidebar/sections.html | 8 ++++++++ layouts/partials/sidebar/tags.html | 5 +++++ layouts/partials/tooltip.html | 4 ++++ layouts/partials/utils/css.html | 5 +++++ layouts/partials/utils/description.html | 6 ++++++ layouts/partials/utils/keywords.html | 6 ++++++ layouts/partials/utils/title.html | 17 ----------------- layouts/sitemap.xml | 5 +++++ tailwind.config.js | 6 ------ 20 files changed, 114 insertions(+), 40 deletions(-) delete mode 100644 layouts/partials/utils/title.html diff --git a/layouts/_default/search.html b/layouts/_default/search.html index 1f9a03e168ab..f4e70cfe061f 100644 --- a/layouts/_default/search.html +++ b/layouts/_default/search.html @@ -35,6 +35,14 @@

{{ .Title }}

window.addEventListener("load", async function () { // Hydrate pagefind pagefind = await import("/pagefind/pagefind.js"); + await pagefind.options({ + ranking: { + termFrequency: 0.2, + pageLength: 0.75, + termSaturation: 1.4, + termSimilarity: 6.0, + }, + }); // Get the query parameter from the URL const urlParams = new URLSearchParams(window.location.search); diff --git a/layouts/index.metadata.json b/layouts/index.metadata.json index e3426bb18d26..acfaf21f2b80 100644 --- a/layouts/index.metadata.json +++ b/layouts/index.metadata.json @@ -1,6 +1,6 @@ [ {{- range where site.Pages "Params.sitemap" "!=" false -}} - {{- $title := partialCached "utils/title.html" . . -}} + {{- $title := .LinkTitle -}} {{- $desc := partialCached "utils/description.html" . . -}} {{- $kwd := partialCached "utils/keywords.html" . . -}} {{- $tags := slice -}} diff --git a/layouts/index.redirects.json b/layouts/index.redirects.json index 5add5074019b..6229dfc8d185 100644 --- a/layouts/index.redirects.json +++ b/layouts/index.redirects.json @@ -1,3 +1,25 @@ +{{- /* + + This template generates the redirects.json file used to generate 301 + redirects in production. It takes all the redirects defined in + data/redirects.yml, as well as all the aliases defined in front matter, and + outputs a simple key-value JSON file: + + { + "": "", + ... + } + + e.g. + + { + "/engine/reference/builder/": "/reference/dockerfile/", + ... + } + + */ +-}} + {{- $redirects := newScratch }} {{- range $i, $e := site.AllPages -}} {{- if .Params.aliases -}} diff --git a/layouts/index.robots.txt b/layouts/index.robots.txt index d3590928c9e8..3e9a658fdf96 100644 --- a/layouts/index.robots.txt +++ b/layouts/index.robots.txt @@ -1,3 +1,9 @@ +{{- /* + For Netlify deployments, we disallow all routes to prevent search + engines from indexing our preview sites. + */ +-}} + {{- if hugo.IsProduction -}} User-agent: * diff --git a/layouts/partials/github-links.html b/layouts/partials/github-links.html index 75ce8d543290..1f7e518b7393 100644 --- a/layouts/partials/github-links.html +++ b/layouts/partials/github-links.html @@ -1,3 +1,8 @@ +{{- /* + Adds links for editing the page or requesting changes: + - "Edit this page": Only in production, skips files from `_vendor/` (upstream repositories). + - "Request changes": Links to a pre-filled issue form. +*/ -}} {{ if hugo.IsProduction }} {{ with .File }} {{ if not (in .Filename "/_vendor/") }} diff --git a/layouts/partials/head.html b/layouts/partials/head.html index cadc04249b8e..0edada5a576b 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -1,16 +1,5 @@ - {{ partial "meta.html" . }} {{- if hugo.IsProduction -}} + diff --git a/layouts/partials/pagemeta.html b/layouts/partials/pagemeta.html index f799522409eb..426897e23e74 100644 --- a/layouts/partials/pagemeta.html +++ b/layouts/partials/pagemeta.html @@ -1,3 +1,10 @@ +{{- /* + Renders a table of contents (ToC) for the page. + - Uses `.Fragments.Headings` to generate a nested ToC if headings exist and `notoc` is not set to `true`. + - Limits heading levels to a min and max range (`$min` and `$max`). + - Wraps the ToC in a `data-pagefind-ignore` container to exclude it from search indexing. + - Includes a recursive template (`walkHeadingFragments`) to handle nested headings. +*/ -}} {{- $toc := false }} {{- with .Fragments }} {{- $toc = and (ne page.Params.notoc true) .Headings }} diff --git a/layouts/partials/search-bar.html b/layouts/partials/search-bar.html index 72da1f4e5c0e..6595e32d3ff7 100644 --- a/layouts/partials/search-bar.html +++ b/layouts/partials/search-bar.html @@ -43,6 +43,14 @@