astro-accelerator 0.3.13 → 0.3.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -1
- package/public/js/search.js +36 -2
- package/public/js/synonyms.js +6 -0
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.3.
|
|
2
|
+
"version": "0.3.15",
|
|
3
3
|
"author": "Steve Fenton",
|
|
4
4
|
"name": "astro-accelerator",
|
|
5
5
|
"description": "A super-lightweight, accessible, SEO-friendly starter project for Astro",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"img": "node --no-experimental-fetch ./src/themes/accelerator/utilities/img.mjs",
|
|
24
24
|
"dev": "node --no-experimental-fetch ./src/themes/accelerator/utilities/img.mjs && astro dev",
|
|
25
25
|
"stats": "node --no-experimental-fetch ./src/themes/accelerator/utilities/stats.mjs",
|
|
26
|
+
"spellcheck": "git fetch origin main:refs/remotes/origin/main && git diff origin/main --name-only --diff-filter=ACMRTUXB | cspell --no-must-find-files --file-list stdin",
|
|
26
27
|
"test": "astro build && npx playwright install --with-deps && npx playwright test",
|
|
27
28
|
"build": "astro build",
|
|
28
29
|
"preview": "astro preview",
|
|
@@ -33,6 +34,7 @@
|
|
|
33
34
|
"@astrojs/mdx": "^1.1.1",
|
|
34
35
|
"astro": "^3.2.4",
|
|
35
36
|
"astro-accelerator-utils": "^0.3.2",
|
|
37
|
+
"cspell": "^7.3.7",
|
|
36
38
|
"csv": "^6.3.5",
|
|
37
39
|
"hast-util-from-selector": "^3.0.0",
|
|
38
40
|
"html-to-text": "^9.0.5",
|
package/public/js/search.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { qs } from './modules/query.js';
|
|
4
4
|
import { raiseEvent } from './modules/events.js';
|
|
5
|
-
import { contains,
|
|
5
|
+
import { contains, sanitise, explode, highlight } from './modules/string.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
@typedef {
|
|
@@ -227,6 +227,40 @@ var dataUrl = qs('#site-search').dataset.sourcedata;
|
|
|
227
227
|
var ready = false;
|
|
228
228
|
var scrolled = false;
|
|
229
229
|
|
|
230
|
+
var _synonyms = null;
|
|
231
|
+
|
|
232
|
+
async function getSynonyms() {
|
|
233
|
+
if (_synonyms != null) {
|
|
234
|
+
return _synonyms;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
try {
|
|
238
|
+
const synonymsModule = await import('./synonyms.js');
|
|
239
|
+
_synonyms =synonymsModule.synonyms;
|
|
240
|
+
} catch {
|
|
241
|
+
_synonyms = {};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return _synonyms;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Replaces synonyms
|
|
249
|
+
* @param {string[]} queryTerms
|
|
250
|
+
*/
|
|
251
|
+
function replaceSynonyms(queryTerms) {
|
|
252
|
+
const synonyms = getSynonyms();
|
|
253
|
+
|
|
254
|
+
for (let i = 0; i < queryTerms.length; i++) {
|
|
255
|
+
const term = queryTerms[i];
|
|
256
|
+
if (synonyms[term] != null) {
|
|
257
|
+
queryTerms[i] = synonyms[term];
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return queryTerms;
|
|
262
|
+
}
|
|
263
|
+
|
|
230
264
|
/**
|
|
231
265
|
* Search term `s` and number of results `r`
|
|
232
266
|
* @param {string} s
|
|
@@ -250,7 +284,7 @@ function search(s, r) {
|
|
|
250
284
|
currentQuery = cleanQuery;
|
|
251
285
|
/** @type {string[]} */
|
|
252
286
|
const stemmedTerms = [];
|
|
253
|
-
const queryTerms = explode(currentQuery);
|
|
287
|
+
const queryTerms = replaceSynonyms(explode(currentQuery));
|
|
254
288
|
|
|
255
289
|
for (const term of queryTerms) {
|
|
256
290
|
const stemmed = stemmer(term);
|