Skip to content

Commit 4327657

Browse files
authored
Merge pull request #237 from chrisrueger/add-pagefind-search
add Pagefind Search for bndtools website
2 parents 0b027d3 + c50bea5 commit 4327657

File tree

8 files changed

+92
-1
lines changed

8 files changed

+92
-1
lines changed

.github/scripts/docs.sh

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ gem --version
44
bundle --version
55

66
bundle exec jekyll build
7+
8+
# create search index under _site/pagefind
9+
./pagefind --verbose --site _site

.github/workflows/cibuild.yml

+12
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ jobs:
3636
with:
3737
ruby-version: 2.7
3838
bundler-cache: true
39+
40+
# Download and install the Pagefind binary
41+
# see releases: https://github.com/CloudCannon/pagefind/releases
42+
- name: Install Pagefind for Search
43+
run: |
44+
curl -L https://github.com/CloudCannon/pagefind/releases/download/v1.3.0/pagefind-v1.3.0-x86_64-unknown-linux-musl.tar.gz \
45+
-o pagefind.tar.gz
46+
tar xzf pagefind.tar.gz
47+
chmod +x pagefind
48+
3949
- name: Build
4050
run: |
4151
./.github/scripts/docs.sh
52+
53+

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
/vendor/
77
/bundler/
88
.jekyll-metadata
9+
pagefind*

README.md

+34
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,40 @@ This should install jekyll and start a local webserver at:
1616

1717
Start editing markdown `.md` files. Jekyll will auto-detect changes and reload the website. Some changes require a restart (e.g. changes to `_config.yml`)
1818

19+
## Local development with Pagefind search
20+
21+
We use https://pagefind.app/ for our search field full text search.
22+
But it is currently not automatically working when using `./run.sh` above, because it works on the
23+
actual build-output on the `_site` folder (which contains the actual `.html` pages).
24+
25+
To test the search locally based on the `_site` folder content, run:
26+
27+
28+
`./run-pagefind-linux.sh`
29+
30+
or
31+
32+
`run-pagefind-macos.sh`
33+
34+
depending on which operating system you are using.
35+
36+
The result should look like:
37+
38+
`Serving "_site" at http://localhost:1414`
39+
40+
41+
The script will download and execute the pagefind executable binary after the build.
42+
Then it will start a small server where you test the result.
43+
Note, that this is different than the `./run.sh` and does not support real-time editing of the content.
44+
45+
Feel free to adjust / extend the start-scripts if you have a different architecture
46+
or to use a different `pagefind` version.
47+
48+
### pagefind for production build via github actions
49+
50+
See the files `.github/workflows/cibuild.yml` and `.github/scripts/docs.sh` for how
51+
building the site and executing `pagefind` is done in the final build on github.
52+
1953
### CSS Styling for Code Highlighter
2054

2155
- jekyll uses `rouge` code highlighter

_config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,5 @@ exclude:
6464
- '.project'
6565
- 'run.sh'
6666
- '/vendor'
67+
- '/pagefind'
6768

_layouts/baselayout.html

+11-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@
77

88
<div class="row main-container">
99

10+
<link href="/pagefind/pagefind-ui.css" rel="stylesheet">
11+
<script src="/pagefind/pagefind-ui.js"></script>
12+
<div id="search"></div>
13+
<script>
14+
window.addEventListener('DOMContentLoaded', (event) => {
15+
new PagefindUI({ element: "#search", showSubResults: true });
16+
});
17+
</script>
18+
1019
<!-- Main Content -->
1120
<div class="large-9 medium-8 medium-push-4 large-push-3 columns">
1221
<div class="off-canvas-wrap move" data-offcanvas>
@@ -21,8 +30,9 @@
2130
</aside>
2231

2332
<!-- main content goes here -->
33+
<main data-pagefind-body>
2434
{{content}}
25-
35+
</main>
2636
<!-- close the off-canvas menu -->
2737
<a class="exit-off-canvas"></a>
2838

run-pagefind-linux.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
set -ev
3+
4+
# Build into _site folder
5+
export BUNDLE_GEMFILE=$PWD/Gemfile
6+
bundle install --jobs=3 --retry=3 --path=vendor
7+
bundle exec jekyll clean
8+
bundle exec jekyll build
9+
10+
# Run and serve the _site folder with search working
11+
# install Linux x86_64
12+
curl -L https://github.com/CloudCannon/pagefind/releases/download/v1.3.0/pagefind-v1.3.0-x86_64-unknown-linux-musl.tar.gz -o pagefind.tar.gz
13+
tar xzf pagefind.tar.gz
14+
chmod +x pagefind
15+
./pagefind --site _site --serve

run-pagefind-macos.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
set -ev
3+
4+
# Build into _site folder
5+
export BUNDLE_GEMFILE=$PWD/Gemfile
6+
bundle install --jobs=3 --retry=3 --path=vendor
7+
bundle exec jekyll clean
8+
bundle exec jekyll build
9+
10+
# Run and serve the _site folder with search working
11+
# install for MacOS aarch64
12+
curl -L https://github.com/CloudCannon/pagefind/releases/download/v1.3.0/pagefind-v1.3.0-aarch64-apple-darwin.tar.gz -o pagefind.tar.gz
13+
tar xzf pagefind.tar.gz
14+
chmod +x pagefind
15+
./pagefind --site _site --serve

0 commit comments

Comments
 (0)