astro-accelerator 0.3.13 → 0.3.14

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.3.13",
2
+ "version": "0.3.14",
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",
@@ -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, containsWord, sanitise, explode, highlight } from './modules/string.js';
5
+ import { contains, sanitise, explode, highlight } from './modules/string.js';
6
6
 
7
7
  /**
8
8
  @typedef {
@@ -227,6 +227,32 @@ var dataUrl = qs('#site-search').dataset.sourcedata;
227
227
  var ready = false;
228
228
  var scrolled = false;
229
229
 
230
+ var synonyms = {};
231
+
232
+ async function getSynonyms() {
233
+ try {
234
+ const synonymsModule = await import('./synonyms.js');
235
+ synonyms =synonymsModule.synonyms;
236
+ } catch {
237
+ synonyms = {};
238
+ }
239
+ }
240
+
241
+ /**
242
+ * Replaces synonyms
243
+ * @param {string[]} queryTerms
244
+ */
245
+ function replaceSynonyms(queryTerms) {
246
+ for (let i = 0; i < queryTerms.length; i++) {
247
+ const term = queryTerms[i];
248
+ if (synonyms[term] != null) {
249
+ queryTerms[i] = synonyms[term];
250
+ }
251
+ }
252
+
253
+ return queryTerms;
254
+ }
255
+
230
256
  /**
231
257
  * Search term `s` and number of results `r`
232
258
  * @param {string} s
@@ -250,7 +276,7 @@ function search(s, r) {
250
276
  currentQuery = cleanQuery;
251
277
  /** @type {string[]} */
252
278
  const stemmedTerms = [];
253
- const queryTerms = explode(currentQuery);
279
+ const queryTerms = replaceSynonyms(explode(currentQuery));
254
280
 
255
281
  for (const term of queryTerms) {
256
282
  const stemmed = stemmer(term);
@@ -0,0 +1,6 @@
1
+ const synonyms = {
2
+ // For example:
3
+ // "licence": "license"
4
+ };
5
+
6
+ export { synonyms };