Skip to content

Commit ac388dc

Browse files
authored
Merge pull request #21853 from dvdksn/tidy-hugo-tpl-2
chore: tidy templates, add comments
2 parents 9e3da36 + 1a9dc69 commit ac388dc

20 files changed

+114
-40
lines changed

layouts/_default/search.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ <h1 class="py-4">{{ .Title }}</h1>
3535
window.addEventListener("load", async function () {
3636
// Hydrate pagefind
3737
pagefind = await import("/pagefind/pagefind.js");
38+
await pagefind.options({
39+
ranking: {
40+
termFrequency: 0.2,
41+
pageLength: 0.75,
42+
termSaturation: 1.4,
43+
termSimilarity: 6.0,
44+
},
45+
});
3846

3947
// Get the query parameter from the URL
4048
const urlParams = new URLSearchParams(window.location.search);

layouts/index.metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{{- range where site.Pages "Params.sitemap" "!=" false -}}
3-
{{- $title := partialCached "utils/title.html" . . -}}
3+
{{- $title := .LinkTitle -}}
44
{{- $desc := partialCached "utils/description.html" . . -}}
55
{{- $kwd := partialCached "utils/keywords.html" . . -}}
66
{{- $tags := slice -}}

layouts/index.redirects.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
{{- /*
2+
3+
This template generates the redirects.json file used to generate 301
4+
redirects in production. It takes all the redirects defined in
5+
data/redirects.yml, as well as all the aliases defined in front matter, and
6+
outputs a simple key-value JSON file:
7+
8+
{
9+
"<request-path>": "<redirect-path>",
10+
...
11+
}
12+
13+
e.g.
14+
15+
{
16+
"/engine/reference/builder/": "/reference/dockerfile/",
17+
...
18+
}
19+
20+
*/
21+
-}}
22+
123
{{- $redirects := newScratch }}
224
{{- range $i, $e := site.AllPages -}}
325
{{- if .Params.aliases -}}

layouts/index.robots.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
{{- /*
2+
For Netlify deployments, we disallow all routes to prevent search
3+
engines from indexing our preview sites.
4+
*/
5+
-}}
6+
17
{{- if hugo.IsProduction -}}
28
User-agent: *
39

layouts/partials/github-links.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
{{- /*
2+
Adds links for editing the page or requesting changes:
3+
- "Edit this page": Only in production, skips files from `_vendor/` (upstream repositories).
4+
- "Request changes": Links to a pre-filled issue form.
5+
*/ -}}
16
{{ if hugo.IsProduction }}
27
{{ with .File }}
38
{{ if not (in .Filename "/_vendor/") }}

layouts/partials/head.html

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
<meta charset="utf-8" />
22
<meta name="viewport" content="width=device-width, initial-scale=1" />
3-
<script type="module">
4-
const pagefind = await import("/pagefind/pagefind.js");
5-
await pagefind.options({
6-
ranking: {
7-
termFrequency: 0.2,
8-
pageLength: 0.75,
9-
termSaturation: 1.4,
10-
termSimilarity: 6.0,
11-
},
12-
});
13-
</script>
143
{{ partial "meta.html" . }}
154
{{- if hugo.IsProduction -}}
165
<script

layouts/partials/meta.html

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
{{ $title := partial "utils/title.html" . }}
21
{{ $description := partial "utils/description.html" . }}
32
{{ if .IsHome }}
43
<title>{{ site.Title }}</title>
54
{{ else }}
65
<title>
7-
{{ printf "%s | %s" $title site.Title }}
6+
{{ printf "%s | %s" .LinkTitle site.Title }}
87
</title>
98
{{ end }}
109
{{ if or (eq .Params.sitemap false) (not hugo.IsProduction) }}
@@ -22,7 +21,7 @@
2221
<meta name="theme-color" content="#2496ed" />
2322

2423
<!-- SEO -->
25-
<meta name="twitter:title" itemprop="title name" content="{{ $title }}" />
24+
<meta name="twitter:title" itemprop="title name" content="{{ .LinkTitle }}" />
2625
<meta
2726
name="twitter:description"
2827
property="og:description"
@@ -38,7 +37,7 @@
3837
content="{{ (resources.Get "images/thumbnail.webp").Permalink }}"
3938
/>
4039
<meta name="twitter:image:alt" content="Docker Documentation" />
41-
<meta property="og:title" content="{{ $title }}" />
40+
<meta property="og:title" content="{{ .LinkTitle }}" />
4241
<meta property="og:description" content="{{ $description }}" />
4342
<meta property="og:type" content="website" />
4443
<meta
@@ -59,4 +58,4 @@
5958
itemprop="datePublished"
6059
content="{{ .PublishDate | default .Lastmod }}"
6160
/>
62-
<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","headline":{{ $title | jsonify }},"description":{{ $description | jsonify }},"url":"{{ .Permalink }}"}</script>
61+
<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","headline":{{ .LinkTitle | jsonify }},"description":{{ $description | jsonify }},"url":"{{ .Permalink }}"}</script>

layouts/partials/pagemeta.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
{{- /*
2+
Renders a table of contents (ToC) for the page.
3+
- Uses `.Fragments.Headings` to generate a nested ToC if headings exist and `notoc` is not set to `true`.
4+
- Limits heading levels to a min and max range (`$min` and `$max`).
5+
- Wraps the ToC in a `data-pagefind-ignore` container to exclude it from search indexing.
6+
- Includes a recursive template (`walkHeadingFragments`) to handle nested headings.
7+
*/ -}}
18
{{- $toc := false }}
29
{{- with .Fragments }}
310
{{- $toc = and (ne page.Params.notoc true) .Headings }}

layouts/partials/search-bar.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@
4343
<script type="module">
4444
window.addEventListener("load", async function () {
4545
const pagefind = await import("/pagefind/pagefind.js");
46+
await pagefind.options({
47+
ranking: {
48+
termFrequency: 0.2,
49+
pageLength: 0.75,
50+
termSaturation: 1.4,
51+
termSimilarity: 6.0,
52+
},
53+
});
4654

4755
const searchBarInput = document.querySelector("#search-bar-input");
4856
const searchBarResults = document.querySelector(

layouts/partials/sidebar/guides.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
{{- /*
2+
Renders a sidebar for pages in the `/guides` section.
3+
- Detects if the current page is part of a multipage guide (`.Store.Set "multipage"`).
4+
- Displays the section's title, summary, languages, tags, and estimated time (`Params.time`).
5+
- Includes a stepper navigation (`guides-stepper.html`) for multipage guides.
6+
- Optionally lists resource links from `Params.resource_links`.
7+
- Provides a link back to the main `/guides/` index.
8+
*/ -}}
19
<div class="flex flex-col gap-4 px-4 pt-2">
210
{{- $root := . }}
311
{{- .Store.Set "multipage" false }}

0 commit comments

Comments
 (0)