Skip to content

Commit b165d0d

Browse files
committed
generate search index in CI job
1 parent e7d0ccc commit b165d0d

363 files changed

Lines changed: 216 additions & 3025 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.githooks/pre-commit

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

.github/workflows/pages.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Build and deploy site
2+
3+
# Builds the Jekyll site, generates the Pagefind search index from the *built*
4+
# site, and deploys the result to GitHub Pages. Because the index is generated
5+
# here on every deploy, it can never drift out of sync with the content (which
6+
# is what happened when the index was hand-committed into the repo).
7+
#
8+
# Requires repo Settings -> Pages -> "Build and deployment" -> Source = "GitHub Actions".
9+
10+
on:
11+
push:
12+
branches: [master]
13+
workflow_dispatch:
14+
15+
permissions:
16+
contents: read
17+
pages: write
18+
id-token: write
19+
20+
# Allow one in-flight deploy at a time; let a running deploy finish rather than
21+
# cancelling it (cancelling a half-published deploy can leave Pages inconsistent).
22+
concurrency:
23+
group: pages
24+
cancel-in-progress: false
25+
26+
jobs:
27+
build:
28+
runs-on: ubuntu-latest
29+
env:
30+
JEKYLL_ENV: production
31+
steps:
32+
- name: Checkout
33+
uses: actions/checkout@v4
34+
35+
- name: Set up Ruby
36+
uses: ruby/setup-ruby@v1
37+
with:
38+
ruby-version: "3.4"
39+
bundler-cache: true
40+
41+
- name: Set up Node
42+
uses: actions/setup-node@v4
43+
with:
44+
node-version: "20"
45+
46+
- name: Build site
47+
run: bundle exec jekyll build
48+
49+
- name: Generate Pagefind search index
50+
run: npx -y pagefind@1.5.2 --site _site
51+
52+
- name: Verify search index exists
53+
run: test -f _site/pagefind/pagefind.js && test -f _site/pagefind/pagefind-entry.json
54+
55+
- name: Upload Pages artifact
56+
uses: actions/upload-pages-artifact@v3
57+
with:
58+
path: _site
59+
60+
deploy:
61+
needs: build
62+
runs-on: ubuntu-latest
63+
environment:
64+
name: github-pages
65+
url: ${{ steps.deployment.outputs.page_url }}
66+
steps:
67+
- name: Deploy to GitHub Pages
68+
id: deployment
69+
uses: actions/deploy-pages@v4

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@
22
config.codekit
33
_site
44
.jekyll-metadata
5-
_stdlib
5+
_stdlib
6+
7+
# Pagefind search index is generated by CI (.github/workflows/pages.yml) on
8+
# every deploy. Never commit it — a hand-committed index drifts out of sync
9+
# with the content and breaks search.
10+
pagefind/

README.md

Lines changed: 21 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -55,52 +55,36 @@ Adding a standard library doc page works almost the same as tutorials.
5555
- Change the `sections` to match the uri of the pages of your tutorial.
5656
* Write your new_doc pages, being sure to update the heading sections as necessary.
5757

58-
## Building Search Index
58+
## Search Index
5959

60-
The site now uses `pagefind` for fully local static search. No external API key is required.
60+
The site uses [`pagefind`](https://pagefind.app/) for fully local static search. No external API key is required.
6161

62-
For GitHub Pages compatibility, the generated `pagefind/` folder is committed to this repository.
62+
**The index is generated automatically by CI on every deploy** — see
63+
[`.github/workflows/pages.yml`](.github/workflows/pages.yml). It builds the
64+
site, runs Pagefind against the *built* `_site`, and deploys the result to
65+
GitHub Pages. Because the index is rebuilt from the actual content on every
66+
deploy, it can never drift out of sync.
6367

64-
1. Build the site:
68+
> **Do not commit a `pagefind/` folder.** It is `.gitignore`d on purpose. A
69+
> hand-committed index drifts from the content and breaks search (you get
70+
> "SEARCH INDEX NOT FOUND" on the live site). Let CI generate it.
6571
66-
`bundler exec jekyll build`
72+
### One-time GitHub setup
6773

68-
2. Generate the search index into `_site/pagefind`:
74+
In repo **Settings → Pages → Build and deployment**, set **Source** to
75+
**"GitHub Actions"**. The workflow then publishes the site (custom domain
76+
`wurstlang.org` is preserved via the `CNAME` file).
6977

70-
`npx -y pagefind --site _site`
71-
72-
3. Sync the generated index into tracked `pagefind/`:
73-
74-
`rm -rf pagefind && cp -R _site/pagefind ./pagefind`
75-
76-
PowerShell equivalent:
77-
78-
`if (Test-Path pagefind) { Remove-Item -Recurse -Force pagefind }; Copy-Item -Recurse _site/pagefind ./pagefind`
79-
80-
4. Serve `_site` (or deploy it). Search will load from `/pagefind/pagefind.js`.
81-
82-
Prerequisite for indexing: Node.js (for `npx pagefind`).
83-
84-
### Pre-commit Hook For Indexing
85-
86-
Set up repo hooks once:
87-
88-
`git config core.hooksPath .githooks`
89-
90-
Then every commit will:
91-
92-
1. Build Jekyll
93-
2. Generate Pagefind index
94-
3. Sync `_site/pagefind` to tracked `pagefind/`
95-
4. Auto-stage `pagefind/`
96-
97-
To bypass once:
78+
### Local dev with `jekyll serve`
9879

99-
`SKIP_PAGEFIND_HOOK=1 git commit ...`
80+
`jekyll serve` does not generate a search index. To preview search locally:
10081

101-
PowerShell equivalent:
82+
1. Build the site: `bundle exec jekyll build`
83+
2. Generate the index into `_site/pagefind`: `npx -y pagefind@1.5.2 --site _site`
84+
3. Serve `_site` (e.g. `npx -y serve _site`). Search loads from `/pagefind/pagefind.js`.
10285

103-
`$env:SKIP_PAGEFIND_HOOK='1'; git commit ...; Remove-Item Env:SKIP_PAGEFIND_HOOK`
86+
Repeat steps 1–2 after content changes you want reflected in local search.
87+
Prerequisite: Node.js (for `npx pagefind`).
10488

10589
### Jenkins
10690

@@ -116,17 +100,3 @@ To use it:
116100
1. Create a Jenkins Pipeline (or Multibranch Pipeline) job for this repository.
117101
2. Keep script source as `Jenkinsfile` in SCM.
118102
3. Ensure the Jenkins agent has Ruby/Bundler and Node.js/npm available.
119-
120-
### Local dev with `jekyll serve`
121-
122-
`jekyll serve` rebuilds `_site`. To keep local search working:
123-
124-
1. Start Jekyll:
125-
126-
`bundler exec jekyll serve`
127-
128-
2. In a second terminal, generate Pagefind index:
129-
130-
`npx -y pagefind --site _site`
131-
132-
3. Repeat step 2 after content changes that should be searchable.

_config.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ exclude:
1919
- assets/plugins/jquery-scrollTo/demo
2020
- assets/plugins/jquery-scrollTo/tests
2121
- assets/plugins/lightbox/examples
22-
keep_files:
23-
- pagefind
2422
repository: wurstscript/wurstscript.github.io
2523
url: https://wurstlang.org
2624
baseurl: ""

_sass/base.scss

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,39 @@ header.branding {
579579
color: var(--text-color-secondary);
580580
}
581581

582+
.local-search-status {
583+
display: flex;
584+
align-items: center;
585+
gap: 8px;
586+
padding: 10px 2px;
587+
color: var(--text-color-secondary);
588+
font-size: 14px;
589+
}
590+
591+
.local-search-error {
592+
color: var(--text-color);
593+
}
594+
595+
.local-search-spinner {
596+
flex: none;
597+
width: 16px;
598+
height: 16px;
599+
border-radius: 50%;
600+
border: 2px solid var(--divider-dark);
601+
border-top-color: var(--color-primary);
602+
animation: local-search-spin 0.6s linear infinite;
603+
}
604+
605+
@keyframes local-search-spin {
606+
to { transform: rotate(360deg); }
607+
}
608+
609+
@media (prefers-reduced-motion: reduce) {
610+
.local-search-spinner {
611+
animation-duration: 1.6s;
612+
}
613+
}
614+
582615
.pagefind-meta {
583616
display: none !important;
584617
}

0 commit comments

Comments
 (0)