Skip to content

Commit 97307d4

Browse files
committed
search: pagefind v1.1.0
Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
1 parent 0845436 commit 97307d4

18 files changed

+91
-85
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ node_modules
66
resources
77
public
88
tmp
9+
static/pagefind

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,15 @@ WORKDIR /test
8383
RUN --mount=type=bind,target=. \
8484
./scripts/test_unused_media.sh
8585

86+
FROM base as pagefind
87+
ARG PAGEFIND_VERSION=1.1.0
88+
COPY --from=build /out ./public
89+
RUN --mount=type=bind,src=pagefind.yml,target=pagefind.yml \
90+
npx pagefind@v${PAGEFIND_VERSION} --output-path "/pagefind"
91+
92+
FROM scratch AS index
93+
COPY --from=pagefind /pagefind .
94+
8695
FROM scratch AS release
8796
COPY --from=build /out /
97+
COPY --from=pagefind /pagefind .

assets/css/global.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
scrollbar-color: theme(colors.gray.dark.800) theme(colors.white / 0.10);
1515
}
1616
}
17+
18+
mark {
19+
@apply bg-amber-light-200 dark:bg-amber-dark-600/25 dark:text-white;
20+
}
1721
}
1822

1923
/* utility classes */

assets/js/src/search.js

Lines changed: 0 additions & 65 deletions
This file was deleted.

docker-bake.hcl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ group "default" {
1717
targets = ["release"]
1818
}
1919

20+
target "index" {
21+
# generate a new local search index
22+
target = "index"
23+
output = ["type=local,dest=static/pagefind"]
24+
}
25+
2026
target "release" {
2127
args = {
2228
HUGO_ENV = HUGO_ENV

hugo_stats.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"Docker-Engine",
4040
"Docker-Hub",
4141
"Download",
42+
"Entra-ID",
4243
"Entra-ID-SAML-2.0",
4344
"Fedora",
4445
"For-Mac-and-Linux",
@@ -54,6 +55,7 @@
5455
"HCL",
5556
"HTTP",
5657
"Heredocs",
58+
"Hub",
5759
"Hyper-V-backend-and-Windows-containers",
5860
"Inline",
5961
"Install-from-the-command-line",
@@ -90,6 +92,7 @@
9092
"Shell",
9193
"Specific-version",
9294
"Svelte",
95+
"Travis-CI",
9396
"Ubuntu",
9497
"Unix-pipe",
9598
"Use-Docker-Init",

layouts/_default/_markup/render-codeblock.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="scroll-mt-20" x-data x-ref="root">
1+
<div data-pagefind-ignore class="scroll-mt-20" x-data x-ref="root">
22
{{ with .Attributes.title }}
33
<div class="text-sm -mb-3 text-gray-light dark:text-gray-dark">{{ . }}</div>
44
{{ end }}

layouts/_default/baseof.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
{{ end }}
3131
</div>
3232
</div>
33-
<div class="min-w-0 px-4 pb-32">
33+
<div data-pagefind-body class="min-w-0 px-4 pb-32">
3434
{{ block "main" . }}
3535
{{ end }}
3636
</div>

layouts/_default/list.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{{ partial "breadcrumbs.html" . }}
77
<article class="prose max-w-none dark:prose-invert">
88
{{ with .Title }}
9-
<h1 class="scroll-mt-36">{{ . }}</h1>
9+
<h1 data-pagefind-weight="10" class="scroll-mt-36">{{ . }}</h1>
1010
{{ end }}
1111
<div class="block lg:hidden">
1212
{{ partial "pagemeta.html" . }}

layouts/_default/single.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{{ partial "breadcrumbs.html" . }}
77
<article class="prose max-w-none dark:prose-invert">
88
{{ with .Title }}
9-
<h1 class="scroll-mt-36">{{ . }}</h1>
9+
<h1 data-pagefind-weight="10" class="scroll-mt-36">{{ . }}</h1>
1010
{{ end }}
1111
<div class="block lg:hidden">
1212
{{ partial "pagemeta.html" . }}

layouts/partials/breadcrumbs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{{ $ctx := . }}
33

44

5-
<nav id="breadcrumbs" class="py-4 gap-4 flex items-center text-gray-light dark:text-gray-dark max-w-full min-w-0">
5+
<nav id="breadcrumbs" data-pagefind-ignore class="py-4 gap-4 flex items-center text-gray-light dark:text-gray-dark max-w-full min-w-0">
66
{{ with ($scratch.GetSortedMapValues "sections") }}
77
{{ range $i, $e := . }}
88
{{- if $i -}}

layouts/partials/head.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,8 @@
7272
}}
7373
<script defer src="{{ $js.Permalink }}"></script>
7474
{{ partialCached "utils/resources.html" "-" }}
75+
{{- /* Highlight text from search results */ -}}
76+
<script type="module">
77+
await import('/pagefind/pagefind-highlight.js');
78+
new PagefindHighlight({ highlightParam: "highlight" });
79+
</script>

layouts/partials/pagemeta.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{{- end }}
55
{{- $tags := .GetTerms "tags" }}
66
{{- if or $toc $tags }}
7-
<div class="not-prose">
7+
<div data-pagefind-ignore class="not-prose">
88
{{- with $tags }}
99
<div class="flex flex-col gap-2 my-2">
1010
<span class="text-lg">Tags</span>

layouts/partials/search.html

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
<!-- search modal -->
2222
<div class="fixed left-0 top-0 z-20 flex w-lvw justify-center py-12 text-gray-light-800 dark:text-gray-dark-800"
2323
role="dialog" tabindex="-1" x-show="open" x-trap="open" x-cloak x-transition>
24-
<div class="max-h-[80vh] overflow-hidden lg:w-[600px] xl:w-[800px] rounded-lg bg-white p-2 mx-8 dark:bg-background-dark w-full flex flex-col"
24+
<div
25+
class="mx-8 flex max-h-[80vh] w-full flex-col overflow-hidden rounded-lg bg-white p-2 dark:bg-background-dark lg:w-[600px] xl:w-[800px]"
2526
@click.away="open = false; document.body.classList.remove('overflow-hidden');">
2627
<div class="m-2 text-xl">Search Docker documentation</div>
2728
<header class="flex items-center py-2">
@@ -42,4 +43,52 @@
4243
<!-- search modal backdrop -->
4344
<div class="fixed left-0 top-0 h-full w-full bg-background-dark/70 dark:bg-gray-dark-100/70" x-show="open" x-cloak>
4445
</div>
46+
<script type="module">
47+
window.addEventListener("load", async function () {
48+
const pagefind = await import("/pagefind/pagefind.js");
49+
await pagefind.options({
50+
ranking: {
51+
termFrequency: 0.2,
52+
pageLength: 0.75,
53+
termSaturation: 1.4,
54+
termSimilarity: 6.0,
55+
},
56+
highlightParam: "highlight",
57+
});
58+
pagefind.init();
59+
60+
const modalSearchInput = document.querySelector("#modal-search-input");
61+
const modalSearchResults = document.querySelector(
62+
"#modal-search-results",
63+
);
64+
65+
async function modalSearch(e) {
66+
const query = e.target.value;
67+
const search = await pagefind.debouncedSearch(query);
68+
if (search === null) {
69+
return;
70+
} else {
71+
const results = await Promise.all(
72+
search.results.map((r) => r.data()),
73+
);
74+
75+
let resultsHTML = `<div>${results.length} results</div>`;
76+
resultsHTML += results
77+
.map((item) => {
78+
return `<div class="bg-gray-light-100 dark:bg-gray-dark-200 rounded p-4">
79+
<div class="flex flex-col">
80+
<a class="link" href="${item.url}">${item.meta.title}</a>
81+
<p class="text-gray-light dark:text-gray-dark">…${item.excerpt}…</p>
82+
</div>
83+
</div>`;
84+
})
85+
.join("");
86+
87+
modalSearchResults.innerHTML = resultsHTML;
88+
}
89+
}
90+
91+
modalSearchInput.addEventListener("input", modalSearch);
92+
});
93+
</script>
4594
</div>

netlify.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ HUGO_ENABLEGITINFO = "true"
99
HUGO_ENVIRONMENT = "preview"
1010

1111
[context.deploy-preview]
12-
command = "hugo --gc --minify -b $DEPLOY_PRIME_URL"
13-
12+
command = "hugo --gc --minify -b $DEPLOY_PRIME_URL && npx pagefind@v1.1.0"

package-lock.json

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@
1515
"homepage": "https://docs.docker.com/",
1616
"dependencies": {
1717
"@alpinejs/collapse": "^3.13.5",
18-
"@alpinejs/persist": "^3.13.5",
1918
"@alpinejs/focus": "^3.13.7",
19+
"@alpinejs/persist": "^3.13.5",
2020
"@floating-ui/dom": "^1.6.3",
2121
"@material-symbols/svg-400": "^0.14.6",
2222
"@tailwindcss/nesting": "^0.0.0-insiders.565cd3e",
2323
"@tailwindcss/typography": "^0.5.10",
2424
"alpinejs": "^3.13.5",
2525
"autoprefixer": "^10.4.17",
26-
"fuse.js": "^7.0.0",
2726
"postcss": "^8.4.33",
2827
"postcss-cli": "^11.0.0",
2928
"postcss-import": "^16.0.0",

pagefind.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output_subdir: pagefind
2+
site: public
3+
exclude_selectors:
4+
- "table"

0 commit comments

Comments
 (0)