Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/checklink.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ jobs:
HUGO_ENVIRONMENT: production
HUGO_ENV: production
run: hugo --environment GitHubPages -d $GITHUB_WORKSPACE/dist --buildFuture
- name: Generate Search index
run: |
node ./assets/js/generate-lunr-index.js $GITHUB_WORKSPACE/dist
- name: Test HTML
uses: wjdp/htmltest-action@master
with:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/hugo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ jobs:
HUGO_ENV: production
run: |
hugo --environment GitHubPages
- name: Generate Search index
run: |
node ./assets/js/generate-lunr-index.js
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ content/en/docs/latest/
content/static/latest/
content/static/**/*.dtmp
content/static/**/*.bkp
content/static/**/*.crswap
content/static/**/*.crswap
content/static/lunr-index.json
54 changes: 54 additions & 0 deletions assets/js/generate-lunr-index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const fs = require('fs');
const lunr = require('lunr');

/**
* This script is used to generate a lunr index from the offline-search-index.json file.
* Hugo must be built before running this script, as jt requires the offline-search-index.json file to have been generated.
*
* The script will output a lunr-index.json file in the content/static directory and the docs directory.
*/

const args = process.argv.slice(2);

// Arguments should only be provided from a pipeline build.
const isFromPipeline = args[0] !== undefined;

const source = isFromPipeline
? args[0]
: "./docs";

const destination = isFromPipeline
? `${args[0]}`
: "./docs";

const data = JSON.parse(fs.readFileSync(`${source}/offline-search-index.json`));

const idx = lunr(function () {
this.ref('ref');
this.field('title', { boost: 5 });
this.field('categories', { boost: 3 });
this.field('tags', { boost: 3 });
this.field('description', { boost: 2 });
this.field('body');

data.forEach((doc) => {
if (doc
&& doc.ref !== undefined
&& !doc.ref.includes('/_shared/')
) {
this.add(doc);
}
});
});

if (!isFromPipeline) {
fs.writeFileSync(`./content/static/lunr-index.json`, JSON.stringify(idx));
}

fs.writeFileSync(`${destination}/lunr-index.json`, JSON.stringify(idx));

// check if file got created
if (!fs.existsSync(`${destination}/lunr-index.json`)) {
console.error('Failed to create lunr index, hugo must be build using `hugo` command before running this script.');
process.exit(1);
}
Loading