Skip to content

Commit e5bbfa4

Browse files
authored
api: use pagefind for search (#56)
Signed-off-by: Nick Santos <[email protected]>
1 parent 686a98e commit e5bbfa4

File tree

10 files changed

+95
-46
lines changed

10 files changed

+95
-46
lines changed

.github/workflows/deploy.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ jobs:
4141
aws-region: us-east-1
4242
- name: Create website api.tilt.dev
4343
run: |
44-
JEKYLL_ENV=production bundle exec jekyll build -d _site
44+
make build-docs
4545
working-directory: docs
4646

4747
- name: Deploy website api.tilt.dev
4848
run: |
49-
aws s3 sync docs/_site s3://prod-collaboration-api.tilt.dev/ --region us-east-1 --delete
49+
aws s3 sync build/docs s3://prod-collaboration-api.tilt.dev/ --region us-east-1 --delete
5050
- name: Invalidate CloudFront cache for api.tilt.dev
5151
run: |
5252
aws cloudfront create-invalidation --distribution-id E2ZQJPGT02CCGI --paths "/*"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
# vendor/
1616

1717
tilt_modules
18+
build

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ base:
2525

2626
update-base:
2727
cd ./base && git fetch && git merge --ff-only origin/master
28+
29+
build-docs:
30+
rm -fR build/docs
31+
docker build -t api-site-base -f deploy/base.dockerfile .
32+
docker buildx build --target static --output type=local,dest=build/docs -f deploy/Dockerfile .

deploy/Dockerfile

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
FROM api-site-base
1+
FROM api-site-base AS sources
22

33
WORKDIR /docs
44

55
COPY ./base/src /base/src/
6-
76
COPY ./docs/Gemfile /docs/Gemfile
87
COPY ./docs/Gemfile.lock /docs/Gemfile.lock
98
RUN bundle install
10-
119
ADD config /config/
1210
ADD docs /docs/
13-
ENTRYPOINT bundle exec jekyll serve --config _config.yml,_config-dev.yml
11+
12+
FROM sources AS static-builder
13+
RUN JEKYLL_ENV=production bundle exec jekyll build -d _site
14+
15+
FROM node:22-alpine as search-builder
16+
RUN npm install -g pagefind
17+
WORKDIR /build
18+
COPY --from=static-builder /docs/_site /build
19+
RUN pagefind --site .
20+
21+
FROM scratch AS static
22+
COPY --from=search-builder /build /
23+
24+
FROM sources
25+
ENTRYPOINT ["bundle", "exec", "jekyll", "serve", "--trace", "--config", "_config.yml,_config-dev.yml"]

deploy/base.dockerfile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
FROM ruby:2.6
1+
FROM ruby:3.2
22

3-
RUN gem install jekyll bundler
3+
# jekyll has weird behavior where it will force things if in the default (development) environment
4+
# so explicitly set a custom one
5+
# see https://github.com/jekyll/jekyll/issues/5743#issuecomment-271396025
6+
ENV JEKYLL_ENV=docker
7+
8+
RUN gem install bundler
9+
RUN gem update --system
10+
RUN gem install jekyll
411

512
WORKDIR /base/src
613

714
ADD ./base/src/Gemfile /base/src/
815
ADD ./base/src/Gemfile.lock /base/src/
916
RUN bundle install
17+
18+
ENTRYPOINT ["jekyll"]

docs/Gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ group :jekyll_plugins do
2424
gem "jekyll-redirect-from"
2525
gem "jekyll-sitemap"
2626
gem "jekyll-seo-tag"
27+
gem "jekyll-tagging"
2728
end
2829

2930
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
@@ -40,7 +41,11 @@ gem "jekyll-inline-svg"
4041
gem "rouge"
4142

4243
# Related posts
44+
gem "jekyll-tagging"
4345
gem "jekyll-tagging-related_posts"
4446

4547
# markdown
4648
gem "kramdown", ">= 2.3.1"
49+
50+
# https://github.com/jekyll/jekyll/issues/8523
51+
gem "webrick"

docs/Gemfile.lock

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
addressable (2.8.0)
5-
public_suffix (>= 2.0.2, < 5.0)
4+
addressable (2.8.2)
5+
public_suffix (>= 2.0.2, < 6.0)
66
colorator (1.1.0)
7-
concurrent-ruby (1.1.9)
7+
concurrent-ruby (1.2.2)
88
em-websocket (0.5.3)
99
eventmachine (>= 0.12.9)
1010
http_parser.rb (~> 0)
1111
eventmachine (1.2.7)
12-
ffi (1.15.4)
12+
ffi (1.15.5)
1313
forwardable-extended (2.6.0)
1414
http_parser.rb (0.8.0)
15-
i18n (1.8.11)
15+
i18n (1.12.0)
1616
concurrent-ruby (~> 1.0)
17-
jekyll (4.2.1)
17+
jekyll (4.2.2)
1818
addressable (~> 2.4)
1919
colorator (~> 1.0)
2020
em-websocket (~> 0.5)
@@ -29,60 +29,60 @@ GEM
2929
rouge (~> 3.0)
3030
safe_yaml (~> 1.0)
3131
terminal-table (~> 2.0)
32-
jekyll-feed (0.15.1)
32+
jekyll-feed (0.17.0)
3333
jekyll (>= 3.7, < 5.0)
34-
jekyll-inline-svg (1.1.4)
34+
jekyll-inline-svg (1.1.5)
3535
jekyll (>= 3.3, < 5.0)
36-
svg_optimizer (~> 0.2.5)
36+
svg_optimizer (~> 0.3.0)
3737
jekyll-paginate (1.1.0)
3838
jekyll-redirect-from (0.16.0)
3939
jekyll (>= 3.3, < 5.0)
40-
jekyll-sass-converter (2.1.0)
40+
jekyll-sass-converter (2.2.0)
4141
sassc (> 2.0.1, < 3.0)
42-
jekyll-seo-tag (2.7.1)
42+
jekyll-seo-tag (2.8.0)
4343
jekyll (>= 3.8, < 5.0)
4444
jekyll-sitemap (1.4.0)
4545
jekyll (>= 3.7, < 5.0)
4646
jekyll-tagging (1.1.0)
4747
nuggets
48-
jekyll-tagging-related_posts (1.1.0)
49-
jekyll (>= 3.5, < 5.0)
50-
jekyll-tagging (~> 1.0)
48+
jekyll-tagging-related_posts (1.3.0)
49+
jekyll (>= 3.9, < 5.0)
5150
jekyll-watch (2.2.1)
5251
listen (~> 3.0)
53-
kramdown (2.3.1)
52+
kramdown (2.4.0)
5453
rexml
5554
kramdown-parser-gfm (1.1.0)
5655
kramdown (~> 2.0)
57-
liquid (4.0.3)
58-
listen (3.7.0)
56+
liquid (4.0.4)
57+
listen (3.8.0)
5958
rb-fsevent (~> 0.10, >= 0.10.3)
6059
rb-inotify (~> 0.9, >= 0.9.10)
6160
mercenary (0.4.0)
6261
minima (2.5.1)
6362
jekyll (>= 3.5, < 5.0)
6463
jekyll-feed (~> 0.9)
6564
jekyll-seo-tag (~> 2.1)
66-
nokogiri (1.13.4-x86_64-linux)
65+
nokogiri (1.18.8-x86_64-linux-gnu)
6766
racc (~> 1.4)
68-
nuggets (1.6.0)
67+
nuggets (1.6.1)
6968
pathutil (0.16.2)
7069
forwardable-extended (~> 2.6)
71-
public_suffix (4.0.6)
72-
racc (1.6.0)
73-
rb-fsevent (0.11.0)
70+
public_suffix (5.0.1)
71+
racc (1.8.1)
72+
rb-fsevent (0.11.2)
7473
rb-inotify (0.10.1)
7574
ffi (~> 1.0)
76-
rexml (3.2.5)
77-
rouge (3.26.1)
75+
rexml (3.3.9)
76+
rouge (3.30.0)
7877
safe_yaml (1.0.5)
7978
sassc (2.4.0)
8079
ffi (~> 1.9)
81-
svg_optimizer (0.2.5)
80+
svg_optimizer (0.3.0)
8281
nokogiri
8382
terminal-table (2.0.0)
8483
unicode-display_width (~> 1.1, >= 1.1.1)
8584
unicode-display_width (1.8.0)
85+
webrick (1.8.2)
8686

8787
PLATFORMS
8888
x86_64-linux
@@ -95,11 +95,13 @@ DEPENDENCIES
9595
jekyll-redirect-from
9696
jekyll-seo-tag
9797
jekyll-sitemap
98+
jekyll-tagging
9899
jekyll-tagging-related_posts
99100
kramdown (>= 2.3.1)
100101
minima (~> 2.0)
101102
rouge
102103
tzinfo-data
104+
webrick
103105

104106
BUNDLED WITH
105107
2.2.32

docs/_layouts/api.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
{% endfor %}
2929
</ul>
3030
</nav>
31-
<form class="Docs-search js-only" action="/search" method="GET">
32-
<input class="Docs-search-input" type="search" name="q" id="q" placeholder="Search Docs" />
31+
<form class="Docs-search js-only" action="/search.html" method="GET">
32+
<input class="Docs-search-input" type="search" name="q" id="q" placeholder="Search API" />
3333
</form>
3434
</header>
3535

docs/search.html

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,32 @@
22
title: Search
33
description: "Search the Tilt documentation"
44
layout: api
5+
hasSearch: true
56
---
67

8+
<div id="pagefind-search"></div>
79
<script>
8-
(function() {
9-
var cx = '017353557192452135467:flbjzvynczi';
10-
var gcse = document.createElement('script');
11-
gcse.type = 'text/javascript';
12-
gcse.async = true;
13-
gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
14-
var s = document.getElementsByTagName('script')[0];
15-
s.parentNode.insertBefore(gcse, s);
16-
})();
10+
window.addEventListener('DOMContentLoaded', (event) => {
11+
const searchEl = document.getElementById('q');
12+
let searchVal = '';
13+
if (searchEl) {
14+
try {
15+
const urlParams = new URLSearchParams(window.location.search);
16+
searchVal = urlParams.get('q');
17+
searchEl.value = urlParams.get('q');
18+
} catch {
19+
// just ignore, search box won't be pre-populated but it's ok
20+
}
21+
}
22+
let ui = new PagefindUI({
23+
element: "#pagefind-search",
24+
showSubResults: false,
25+
showImages: false,
26+
});
27+
ui.triggerSearch(searchVal);
28+
});
1729
</script>
18-
<gcse:searchresults-only></gcse:searchresults-only>
30+
31+
<noscript>
32+
JavaScript is required for search functionality.
33+
</noscript>

0 commit comments

Comments
 (0)