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 +1 -1
- package/public/js/modules/search-dialog.js +14 -2
- package/public/js/search.js +11 -10
package/package.json
CHANGED
|
@@ -41,13 +41,25 @@ function enhanceSearchIcon() {
|
|
|
41
41
|
document.body.appendChild(dialog);
|
|
42
42
|
document.body.appendChild(scr);
|
|
43
43
|
|
|
44
|
-
|
|
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
|
});
|
package/public/js/search.js
CHANGED
|
@@ -323,8 +323,7 @@ async function search(s, r) {
|
|
|
323
323
|
|
|
324
324
|
cleanQuery.length > 0 && haystack.forEach( (item) => {
|
|
325
325
|
|
|
326
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
409
|
+
item.foundWords += foundWords;
|
|
409
410
|
|
|
410
411
|
if (item.score > 0) {
|
|
411
412
|
needles.push(item);
|