astro-accelerator 0.3.25 → 0.3.27

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.25",
2
+ "version": "0.3.27",
3
3
  "author": "Steve Fenton",
4
4
  "name": "astro-accelerator",
5
5
  "description": "A super-lightweight, accessible, SEO-friendly starter project for Astro",
@@ -41,13 +41,25 @@ function enhanceSearchIcon() {
41
41
  document.body.appendChild(dialog);
42
42
  document.body.appendChild(scr);
43
43
 
44
- icon.addEventListener('click', (e) => {
44
+ function openSearch(e) {
45
45
  e.preventDefault();
46
46
  dialog.showModal();
47
47
  icon.setAttribute('aria-expanded', 'true');
48
48
  return false;
49
- });
49
+ }
50
+
51
+ // Open search on CTRL + SPACE
52
+ window.onkeydown = function(e) {
53
+ if (e.ctrlKey && e.key == ' ') {
54
+ return openSearch(e);
55
+ }
56
+ if (e.ctrlKey) return false;
57
+ };
58
+
59
+ // Open search on click
60
+ icon.addEventListener('click', openSearch);
50
61
 
62
+ // Close dialog
51
63
  close.addEventListener('click', () => dialog.close());
52
64
  dialog.addEventListener('close', () => icon.setAttribute('aria-expanded', 'false'));
53
65
  });
@@ -323,8 +323,7 @@ async function search(s, r) {
323
323
 
324
324
  cleanQuery.length > 0 && haystack.forEach( (item) => {
325
325
 
326
- let foundWords = 0;
327
- let isPhraseFound = false;
326
+ item.foundWords = 0;
328
327
  item.score = 0;
329
328
  item.matchedHeadings = [];
330
329
 
@@ -333,9 +332,13 @@ async function search(s, r) {
333
332
  // Part 1 - Phrase Matches, i.e. "Kitchen Sink"
334
333
 
335
334
  // Title
335
+ if (item.safeTitle === currentQuery) {
336
+ item.foundWords += 2;
337
+ }
338
+
336
339
  if (contains(item.safeTitle, currentQuery)) {
337
340
  item.score = item.score + scoring.phraseTitle;
338
- isPhraseFound = true;
341
+ item.foundWords += 2;
339
342
  }
340
343
 
341
344
  // Headings
@@ -343,21 +346,19 @@ async function search(s, r) {
343
346
  if (contains(c.safeText, currentQuery)) {
344
347
  item.score = item.score + scoring.phraseHeading;
345
348
  item.matchedHeadings.push(c);
346
- isPhraseFound = true;
349
+ item.foundWords++;
347
350
  }
348
351
  });
349
352
 
350
353
  // Description
351
354
  if (contains(item.description, currentQuery)) {
352
355
  item.score = item.score + scoring.phraseDescription;
353
- isPhraseFound = true;
354
- }
355
-
356
- if (isPhraseFound) {
357
- foundWords++;
356
+ item.foundWords++;
358
357
  }
359
358
 
360
359
  // Part 2 - Term Matches, i.e. "Kitchen" or "Sink"
360
+
361
+ let foundWords = 0;
361
362
 
362
363
  allTerms.forEach(term => {
363
364
  let isTermFound = false;
@@ -405,7 +406,7 @@ async function search(s, r) {
405
406
  }
406
407
  });
407
408
 
408
- item.foundWords = foundWords;
409
+ item.foundWords += foundWords;
409
410
 
410
411
  if (item.score > 0) {
411
412
  needles.push(item);