Skip to content

Commit 17378ab

Browse files
committed
Switch to pagefind for search
We have more control over search indices if we use a local search library
1 parent ec777b4 commit 17378ab

File tree

8 files changed

+351
-157
lines changed

8 files changed

+351
-157
lines changed

.github/workflows/main.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ jobs:
2121
uses: actions/setup-go@v6
2222
with:
2323
go-version: '1.x'
24+
# Node is used to generate the pagefind index
25+
- name: Setup Node.js environment
26+
uses: actions/setup-node@v6
27+
with:
28+
node-version: 'latest'
2429
- name: Install Dependencies
2530
run: sudo apt-get install make curl jq
2631
- name: Install pack

Makefile

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,9 @@ TOOLS_BIN:=tools/bin
3030
$(TOOLS_BIN):
3131
mkdir $(TOOLS_BIN)
3232

33-
# adapted from https://stackoverflow.com/a/12099167/552902
3433
HUGO_OS:=Linux
35-
HUGO_ARCH:=32bit
34+
HUGO_ARCH:=64bit
3635
HUGO_EXT:=tar.gz
37-
ifeq ($(OS),Windows_NT)
38-
HUGO_OS:=Windows
39-
HUGO_EXT:=zip
40-
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
41-
HUGO_ARCH:=64bit
42-
endif
43-
endif
4436

4537
ifeq ($(shell uname -s),Darwin)
4638
HUGO_OS:=darwin
@@ -135,6 +127,8 @@ build: export PACK_VERSION:=$(PACK_VERSION)
135127
build: $(HUGO_BIN) pack-version pack-docs-update
136128
@echo "> Building..."
137129
$(HUGO_BIN)
130+
# Github Workflows ensures `node` is installed.
131+
npx run pagefind --source ./public --destination ./public/pagefind
138132

139133
.PHONY: test
140134
test: install-pack-cli check-pack-cli-version install-ugo

themes/buildpacks/assets/scss/components/_algolia.scss

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

themes/buildpacks/assets/scss/site.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
@import 'code';
77
@import 'syntax';
88

9-
@import 'components/algolia';
109
@import 'components/header';
1110
@import 'components/hero';
1211
@import 'components/grid';

themes/buildpacks/layouts/_default/baseof.html

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
{{ $style := resources.Get "scss/site.scss" | toCSS }}
1818
<link rel="stylesheet" href="{{ $style.Permalink }}" integrity="{{ $style.Data.Integrity }}" media="screen">
1919

20-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css" />
21-
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js"></script>
20+
<link rel="stylesheet" href="/pagefind/pagefind-ui.css">
21+
<script src="/pagefind/pagefind-ui.js"></script>
2222

2323
<script async src="https://www.googletagmanager.com/gtag/js?id=G-CJLSR4FQXL"></script>
2424
<link rel="stylesheet"
@@ -35,31 +35,6 @@
3535
}
3636
</style>
3737

38-
<script>
39-
$(function () {
40-
$('h1[id], h2[id], h3[id], h4[id], h5[id]').not(':has(a)').each(function () {
41-
this.innerHTML =
42-
`<a href="#${this.id}" class="h-anchor">
43-
${this.innerHTML} <i class="fas fa-link icon" aria-label="Anchor"></i>
44-
</a>`;
45-
});
46-
47-
if ($('input#search').length > 0) {
48-
docsearch({
49-
apiKey: '5c00a51f166dab99e1cc6e0a9976e9f9',
50-
indexName: 'buildpacks',
51-
inputSelector: 'input#search',
52-
debug: false
53-
});
54-
}
55-
});
56-
57-
window.dataLayer = window.dataLayer || [];
58-
function gtag() { dataLayer.push(arguments); }
59-
gtag('js', new Date());
60-
gtag('config', 'G-CJLSR4FQXL');
61-
</script>
62-
6338
<title>{{ .Title | plainify }} · {{ .Site.Title }}</title>
6439
</head>
6540

themes/buildpacks/layouts/partials/sidebar.html

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
{{- $currentNode := . -}}
22

33
<nav class='sidebar'>
4-
<form class="pt-1 pb-3 pl-2 pr-3 border-bottom">
5-
<input id="search" class="form-control" type="search" placeholder="Search..." aria-label="Search">
6-
</form>
4+
<div id="search"></div>
5+
<script>
6+
window.addEventListener('DOMContentLoaded', (event) => {
7+
new PagefindUI({
8+
element: "#search",
9+
showSubResults: true,
10+
bundlePath: "/pagefind/"
11+
});
12+
});
13+
</script>
714
{{ with .Site.GetPage "/docs" }}
815
{{- $home := . -}}
916
<ul>

0 commit comments

Comments
 (0)