Skip to content

Commit 5e6798a

Browse files
committed
Remove ignored file from tracking
1 parent d748401 commit 5e6798a

File tree

4 files changed

+31
-17
lines changed

4 files changed

+31
-17
lines changed

assets/js/generate-lunr-index.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ const fs = require('fs');
22
const lunr = require('lunr');
33

44
const args = process.argv.slice(2);
5-
const destination = args[0] ?? ".";
5+
const destination = args[0] === undefined
6+
? "./docs"
7+
: args[0];
68

7-
const data = JSON.parse(fs.readFileSync(`${destination}/docs/offline-search-index.json`));
9+
const data = JSON.parse(fs.readFileSync(`${destination}/offline-search-index.json`));
810

911
const idx = lunr(function () {
1012
this.ref('ref');
@@ -14,7 +16,7 @@ const idx = lunr(function () {
1416
this.field('description', { boost: 2 });
1517
this.field('body');
1618

17-
data.forEach((doc) => {let docToAdd;
19+
data.forEach((doc) => {
1820
if (doc
1921
&& doc.ref !== undefined
2022
&& !doc.ref.includes('/_shared/')
@@ -24,10 +26,10 @@ const idx = lunr(function () {
2426
});
2527
});
2628

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

2931
// check if file got created
30-
if (!fs.existsSync(`${destination}/assets/json/lunr-index.json`)) {
32+
if (!fs.existsSync(`${destination}/lunr-index.json`)) {
3133
console.error('Failed to create lunr index');
3234
process.exit(1);
3335
}

assets/js/offline-search.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
2828

2929
if (window.Worker) {
3030
worker = new Worker('/js/worker.js');
31-
const url = '/json/lunr-index.json';
31+
const url = '/lunr-index.json';
3232

33-
worker.postMessage({
34-
type: 'init',
35-
lunrIndexUrl: url,
36-
rawIndexUrl: $searchInput.data('offline-search-index-json-src')
33+
worker.postMessage({
34+
type: 'init',
35+
currentPath: window.location.pathname,
36+
lunrIndexUrl: url,
37+
rawIndexUrl: $searchInput.data('offline-search-index-json-src')
3738
});
3839

3940
worker.onerror = function (error) {
@@ -142,7 +143,11 @@
142143
return;
143144
}
144145

145-
worker.postMessage({ type: 'search', query: searchQuery, maxResults: $targetSearchInput.data('offline-search-max-results') });
146+
worker.postMessage({
147+
type: 'search',
148+
query: searchQuery,
149+
maxResults: $targetSearchInput.data('offline-search-max-results')
150+
});
146151
};
147152

148153
//

assets/js/worker.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,29 @@ if (typeof importScripts === 'function') {
33
}
44

55
let idx;
6+
const versionRegex = new RegExp("^\/docs\/([0-9\.]*|latest)\/");
67
const resultDetails = new Map(); // Will hold the data for the search results (titles and summaries)
78
let indexReadyPromise;
89

910
// Initialize the index
1011
self.onmessage = async function (event) {
1112
if (event.data.type === 'init') {
13+
const regexResults = versionRegex.exec(event.data.currentPath);
14+
const version = regexResults
15+
? regexResults[1]
16+
: undefined;
1217
indexReadyPromise = new Promise(async (resolve, reject) => {
1318
try {
1419
const rawIndex = await fetch(event.data.rawIndexUrl);
1520
let json = await rawIndex.json();
1621
json.forEach((doc) => {
17-
resultDetails.set(doc.ref, {
18-
version: doc.version,
19-
title: doc.title,
20-
excerpt: doc.excerpt,
21-
});
22+
if (version === undefined || doc.ref.startsWith(version)) {
23+
resultDetails.set(doc.ref, {
24+
version: doc.version,
25+
title: doc.title,
26+
excerpt: doc.excerpt,
27+
});
28+
}
2229
});
2330

2431
const lunrIndex = await fetch(event.data.lunrIndexUrl);
@@ -51,6 +58,7 @@ self.onmessage = async function (event) {
5158
});
5259
});
5360
})
61+
.filter((result) => resultDetails.has(result.ref))
5462
.slice(0, event.data.maxResults);
5563

5664
const docs = new Map();

assets/json/lunr-index.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)