Skip to content

Commit 9e0e1e1

Browse files
docs(DocSearch): integrate Algolia DocSearch for better developer experience (#148)
* docs: integrate Algolia DocSearch (fixes #147) * feat(.gitignore): ignore .env files * feat(docusaurus.config.js, .env.example): update to match Algolia env vars * feat(deploy.yml): update to expose Algolia env vars during docs build * docs: add Algolia DocSearch and env example notes * docs(getting-started): enhance clarity, wording & code examples --------- Co-authored-by: Ryan-Millard <millardryandevon@gmail.com>
1 parent 554d030 commit 9e0e1e1

File tree

9 files changed

+97
-46
lines changed

9 files changed

+97
-46
lines changed

.github/workflows/deploy.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ jobs:
4141
run: npm run build
4242

4343
- name: Build Docusaurus site
44+
env:
45+
ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }}
46+
ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }}
47+
ALGOLIA_INDEX_NAME: ${{ secrets.ALGOLIA_INDEX_NAME }}
4448
run: |
4549
cd docs
4650
npm ci

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ dist-ssr
2828

2929
src/data/contributor-credits.json
3030

31+
.env
3132
# CMake build artifacts
3233
src/wasm/cmake-build/
3334
src/wasm/**/CMakeCache.txt

docs/.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ALGOLIA_APP_ID=
2+
ALGOLIA_API_KEY=
3+
ALGOLIA_INDEX_NAME=

docs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
# Misc
1212
.DS_Store
13+
.env
1314
.env.local
1415
.env.development.local
1516
.env.test.local

docs/docs/introduction/_category_.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"label": "📖 Introduction",
33
"position": 2,
44
"link": {
5-
"type": "generated-index"
6-
}
5+
"type": "generated-index",
6+
"title": "Introduction Overview",
7+
"description": "A brief usage overview and introduction to development in Img2Num."
8+
},
9+
"collapsed": false
710
}

docs/docs/introduction/getting-started.md

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ The section below will guide you through installing Docker on your operating sys
161161
</TabItem>
162162

163163
</Tabs>
164-
165164
</TabItem>
166165

167166
<TabItem value="local" label="Local / Manual Setup">
@@ -258,6 +257,12 @@ You can choose to only install the dependencies for one portion of the app, but
258257
In order to call the `img2num` script that we will be using for Docker in the following sections,
259258
you need to stay in the root directory of the project since that is where the file is.
260259
:::
260+
:::tip For Experienced Docker users
261+
You can skip using the `img2num` script if you prefer using plain Docker commands -
262+
the script is intended to help developers who don't want to use Docker directly.
263+
264+
It is recommended that you read the contents of the file for examples of the commands you can use.
265+
:::
261266
<Tabs groupId="setup-scripts" defaultValue="bash">
262267
<TabItem value="bash" label="Bash (Linux / macOS / WSL / Git Bash)" default>
263268
```bash title="Install all dependencies"
@@ -267,24 +272,42 @@ You can choose to only install the dependencies for one portion of the app, but
267272
268273
./img2num npm install --prefix ./docs
269274
```
275+
276+
:::info
277+
```bash title="Try passing -h or --help as an argument to see the list of available script arguments"
278+
./img2num -h # or --help (they are are the same)
279+
```
280+
:::
270281
</TabItem>
271282

272283
<TabItem value="batch" label="Batch (Windows CMD)">
273-
```bash title="Install all dependencies"
284+
```bat title="Install all dependencies"
274285
cd Img2Num
275286
.\img2num.bat npm install
276287
277288
.\img2num.bat npm install --prefix ./docs
278289
```
290+
291+
:::info
292+
```bat title="Try passing -h or --help as an argument to see the list of available script arguments"
293+
.\img2num.bat -h REM or --help (they are are the same)
294+
```
295+
:::
279296
</TabItem>
280297

281298
<TabItem value="powershell" label="PowerShell">
282-
```bash title="Install all dependencies"
299+
```ps1 title="Install all dependencies"
283300
cd Img2Num
284301
.\img2num.ps1 npm install
285302
286303
.\img2num.ps1 npm install --prefix ./docs
287304
```
305+
306+
:::info
307+
```ps1 title="Try passing -h or --help as an argument to see the list of available script arguments"
308+
.\img2num.ps1 -h # or --help (they are are the same)
309+
```
310+
:::
288311
</TabItem>
289312
</Tabs>
290313
</TabItem>
@@ -376,6 +399,20 @@ You can choose to only install the dependencies for one portion of the app, but
376399
</TabItem>
377400
</Tabs>
378401

402+
### Docs Search (Algolia DocSearch)
403+
404+
The documentation site ships with `Algolia DocSearch` already configured.
405+
**You do not need Algolia credentials** to run the docs locally. If you do not provide credentials,
406+
the search box will be inactive in local development, which is expected.
407+
408+
:::info
409+
You can ignore this feature as it only affects production builds.
410+
:::
411+
412+
### Environment variables (.env.example)
413+
414+
The docs site includes a `docs/.env.example` file to document the optional Algolia environment variables. For local development, you can safely leave these values blank, and you should never commit real secrets to the repository.
415+
379416
## Running the app for the first time
380417

381418
This section will help you run both the main application and the documentation site for the first time.

docs/docusaurus.config.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,33 @@
44
// There are various equivalent ways to declare your Docusaurus config.
55
// See: https://docusaurus.io/docs/api/docusaurus-config
66

7+
import { createRequire } from 'module';
78
import { themes as prismThemes } from 'prism-react-renderer';
89
import path from 'path';
910
import webpackAliasPlugin from './plugins/webpack-alias/index.js';
1011
import { changelogSidebarGenerator } from './changelogSidebarGenerator.js';
1112
import remarkMath from 'remark-math';
1213
import rehypeKatex from 'rehype-katex';
1314

14-
// This runs in Node.js - Don't use client-side code here (browser APIs, JSX...)
15+
const require = createRequire(import.meta.url);
16+
require('dotenv').config();
17+
18+
const hasAlgoliaEnvDefined = process.env.ALGOLIA_APP_ID
19+
&& process.env.ALGOLIA_API_KEY
20+
&& process.env.ALGOLIA_INDEX_NAME;
21+
const algolia =
22+
hasAlgoliaEnvDefined
23+
? {
24+
appId: process.env.ALGOLIA_APP_ID,
25+
apiKey: process.env.ALGOLIA_API_KEY,
26+
indexName: process.env.ALGOLIA_INDEX_NAME,
27+
contextualSearch: true,
28+
}
29+
: undefined;
30+
const algoliaHeadTag = {
31+
name: 'algolia-site-verification',
32+
content: 'DB4B5FEC1545D32B',
33+
};
1534

1635
/** @type {import('@docusaurus/types').Config} */
1736
const config = {
@@ -124,6 +143,13 @@ const config = {
124143
colorMode: {
125144
respectPrefersColorScheme: true,
126145
},
146+
147+
metadata: [
148+
algoliaHeadTag,
149+
],
150+
151+
algolia,
152+
127153
navbar: {
128154
title: 'Img2Num',
129155
logo: {

0 commit comments

Comments
 (0)