Skip to content

Commit f3b0d8d

Browse files
committed
Add search using Typesense
1 parent e5d60a1 commit f3b0d8d

9 files changed

Lines changed: 4824 additions & 3247 deletions

.env.typesense.sample

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Example Local Docker:
2+
#
3+
# For Local Docker, the TYPESENSE_API_KEY and TYPESENSE_SEARCH_API_KEY
4+
# are the same as there's only one key to the local Typesense instance.
5+
#
6+
# TYPESENSE_API_KEY=local_typesense_admin
7+
# TYPESENSE_HOST=host.docker.internal
8+
# TYPESENSE_PORT=8108
9+
# TYPESENSE_PROTOCOL=http
10+
# TYPESENSE_SEARCH_API_KEY=local_typesense_admin
11+
12+
# Example Typesense Cloud:
13+
#
14+
# For Typesense Cloud, the TYPESENSE_API_KEY needs to have write access
15+
# to the Typesense cluster because it's used by the scraper to index the
16+
# content, while the TYPESENSE_SEARCH_API_KEY needs to have read-only
17+
# access to the Typesense cluster because it's used by the browser to
18+
# perform search queries.
19+
#
20+
# TYPESENSE_API_KEY=<ADMIN_TYPESENSE_API_KEY>
21+
# TYPESENSE_HOST=<TYPESENSE_CLUSTER.a1.typesense.net>
22+
# TYPESENSE_PORT=443
23+
# TYPESENSE_PROTOCOL=https
24+
# TYPESENSE_SEARCH_API_KEY=<READ_ONLY_TYPESENSE_API_KEY>
25+
26+
TYPESENSE_API_KEY=
27+
TYPESENSE_HOST=
28+
TYPESENSE_PORT=
29+
TYPESENSE_PROTOCOL=
30+
TYPESENSE_SEARCH_API_KEY=

.github/workflows/deploy.docusaurus.yml

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
pull-requests: write
1616

1717
steps:
18-
- name: Checkout code
18+
- name: Checkout Code
1919
uses: actions/checkout@v3
2020

2121
- name: Setup Node.js
@@ -24,11 +24,21 @@ jobs:
2424
node-version: 18
2525
cache: npm
2626

27-
- name: Install dependencies
27+
- name: Install Dependencies
2828
run: npm ci
2929

3030
- name: Build
3131
run: npm run build
32+
env:
33+
TYPESENSE_HOST: ${{ secrets.TYPESENSE_HOST }}
34+
TYPESENSE_PORT: 443
35+
TYPESENSE_PROTOCOL: https
36+
TYPESENSE_SEARCH_API_KEY: ${{ secrets.TYPESENSE_SEARCH_API_KEY }}
37+
38+
- name: Write Deployment Marker
39+
if: github.ref == 'refs/heads/master'
40+
run: |
41+
printf '{"deploymentId":"%s"}\n' '${{ github.run_id }}' > build/deployment.json
3242
3343
- name: Publish to Cloudflare Pages
3444
id: cloudflare-pages
@@ -39,7 +49,31 @@ jobs:
3949
projectName: topper-docs
4050
directory: build
4151

42-
- name: Add comment
52+
- name: Wait for Deployment
53+
if: github.ref == 'refs/heads/master'
54+
run: |
55+
for attempt in $(seq 1 30); do
56+
if curl -fsS "https://docs.topperpay.com/deployment.json?run=${{ github.run_id }}&attempt=$attempt" | grep -F '"deploymentId":"${{ github.run_id }}"' > /dev/null; then
57+
exit 0
58+
fi
59+
60+
echo "Site not updated yet, retrying ($attempt/30)."
61+
sleep 10
62+
done
63+
64+
echo "Timed out waiting for https://docs.topperpay.com/deployment.json to serve deploymentId ${{ github.run_id }}."
65+
exit 1
66+
67+
- name: Index Docs in Typesense
68+
if: github.ref == 'refs/heads/master'
69+
run: npm run index
70+
env:
71+
TYPESENSE_API_KEY: ${{ secrets.TYPESENSE_API_KEY }}
72+
TYPESENSE_HOST: ${{ secrets.TYPESENSE_HOST }}
73+
TYPESENSE_PORT: 443
74+
TYPESENSE_PROTOCOL: https
75+
76+
- name: Add Comment
4377
uses: mshick/add-pr-comment@v2
4478
with:
4579
message: |
@@ -48,5 +82,5 @@ jobs:
4882
| Name | Link |
4983
|------ | ---- |
5084
| <span aria-hidden="true">🔨</span> Commit SHA | ${{ github.sha }} |
51-
| <span aria-hidden="true">🔍</span> Deploy log | ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
85+
| <span aria-hidden="true">🔍</span> Deploy Log | ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
5286
| <span aria-hidden="true">🚀</span> Preview URL | [${{ steps.cloudflare-pages.outputs.url }}](${{ steps.cloudflare-pages.outputs.url }}) |

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
/build
2-
.docusaurus
31
.cache-loader
2+
.docusaurus
3+
.env.typesense
4+
/build
5+
/typesense-data
46
node_modules

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# topper-docs
22

3-
Public developer documentation for business users integrating with topper, built using [Docusaurus](https://docusaurus.io/).
3+
Public developer documentation for business users integrating with Topper, built using [Docusaurus](https://docusaurus.io/).
44

5-
## Running locally
5+
## Running Locally
66

77
```sh
88
npm install

docusaurus.config.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
const darkCodeTheme = require('prism-react-renderer').themes.dracula;
22
const lightCodeTheme = require('prism-react-renderer').themes.github;
33

4+
const typesenseHost = process.env.TYPESENSE_HOST ?? 'localhost';
5+
const typesensePort = parseInt(process.env.TYPESENSE_PORT, 10) || 8108;
6+
const typesenseProtocol = process.env.TYPESENSE_PROTOCOL ?? 'http';
7+
const isLocalTypesense = (typesenseHost === 'localhost' || typesenseHost === 'host.docker.internal') && typesenseProtocol === 'http';
8+
const typesenseSearchApiKey = process.env.TYPESENSE_SEARCH_API_KEY ?? (isLocalTypesense ? 'local_typesense_admin' : undefined);
9+
410
const config = {
511
baseUrl: '/',
612
favicon: 'images/favicon.ico',
@@ -44,10 +50,23 @@ const config = {
4450
darkTheme: darkCodeTheme,
4551
theme: lightCodeTheme,
4652
additionalLanguages: ['java', "go", "python", "php"]
53+
},
54+
typesense: {
55+
contextualSearch: true,
56+
typesenseCollectionName: 'topper_docs', // Must match `index_name` in `typesense-docsearch-config.json`.
57+
typesenseServerConfig: {
58+
apiKey: typesenseSearchApiKey,
59+
nodes: [{
60+
host: typesenseHost,
61+
port: typesensePort,
62+
protocol: typesenseProtocol
63+
}],
64+
}
4765
}
4866
},
49-
title: 'Topper - Developer docs',
50-
url: 'https://docs.topperpay.com'
67+
themes: ['docusaurus-theme-search-typesense'],
68+
title: 'Topper - Developer Docs',
69+
url: process.env.TOPPER_DOCS_URL ?? 'https://docs.topperpay.com'
5170
};
5271

5372
module.exports = config;

0 commit comments

Comments
 (0)