astro-accelerator 0.0.96 → 0.0.99

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.0.96",
2
+ "version": "0.0.99",
3
3
  "author": "Steve Fenton",
4
4
  "name": "astro-accelerator",
5
5
  "description": "A super-lightweight, accessible, SEO-friendly starter project for Astro",
@@ -24,9 +24,9 @@
24
24
  "dts": "tsc ./tests/locate-content.js ./tests/locate-navigation.js ./tests/locate-search.js --allowJs --declaration --emitDeclarationOnly"
25
25
  },
26
26
  "dependencies": {
27
- "@astrojs/mdx": "^0.19.6",
28
- "astro": "^2.5.7",
29
- "astro-accelerator-utils": "^0.2.28",
27
+ "@astrojs/mdx": "^0.19.7",
28
+ "astro": "^2.7.2",
29
+ "astro-accelerator-utils": "^0.2.29",
30
30
  "hast-util-from-selector": "^2.0.1",
31
31
  "html-to-text": "^9.0.5",
32
32
  "keyword-extractor": "^0.0.25",
@@ -34,7 +34,7 @@
34
34
  "sharp": "^0.32.1"
35
35
  },
36
36
  "devDependencies": {
37
- "@playwright/test": "^1.31.2"
37
+ "@playwright/test": "^1.35.1"
38
38
  },
39
39
  "engines": {
40
40
  "node": "*"
@@ -54,6 +54,7 @@ function search(s) {
54
54
 
55
55
  s.length > 0 && haystack.forEach( (item) => {
56
56
 
57
+ let foundWords = 0;
57
58
  item.score = 0;
58
59
  item.matchedHeadings = [];
59
60
 
@@ -82,15 +83,20 @@ function search(s) {
82
83
  // Part 2 - Term Matches, i.e. "Kitchen" or "Sink"
83
84
 
84
85
  queryTerms.forEach(term => {
86
+ let isTermFound = false;
87
+
85
88
  // Title
86
89
  if (contains(item.safeTitle, term)) {
87
90
  item.score = item.score + 40;
91
+ isTermFound = true;
88
92
  }
89
93
 
90
94
  // Headings
91
95
  item.headings.forEach(c => {
92
96
  if (contains(c.safeText, term)) {
93
97
  item.score = item.score + 15;
98
+ isTermFound = true;
99
+
94
100
  if (item.matchedHeadings.filter(h => h.slug == c.slug).length == 0) {
95
101
  item.matchedHeadings.push(c);
96
102
  }
@@ -99,21 +105,30 @@ function search(s) {
99
105
 
100
106
  // Description
101
107
  if (contains(item.description, term)) {
108
+ isTermFound = true;
102
109
  item.score = item.score + 15;
103
110
  }
104
111
 
105
112
  // Tags
106
113
  item.tags.forEach(t => {
107
114
  if (contains(t, term)) {
115
+ isTermFound = true;
108
116
  item.score = item.score + 15;
109
117
  }
110
118
  });
111
119
 
112
120
  // Keywords
113
121
  if (contains(item.keywords, term)) {
122
+ isTermFound = true;
114
123
  item.score = item.score + 15;
115
124
  }
116
- })
125
+
126
+ if (isTermFound) {
127
+ foundWords++;
128
+ }
129
+ });
130
+
131
+ item.foundWords = foundWords / queryTerms.length;
117
132
 
118
133
  if (item.score > 0) {
119
134
  needles.push(item);
@@ -121,7 +136,11 @@ function search(s) {
121
136
  });
122
137
 
123
138
  needles.sort(function (a, b){
124
- return b.score - a.score;
139
+ if (b.foundWords === a.foundWords) {
140
+ return b.score - a.score;
141
+ }
142
+
143
+ return b.foundWords - a.foundWords;
125
144
  });
126
145
 
127
146
  const total = needles.reduce(function (accumulator, needle) {
package/src/env.d.ts DELETED
@@ -1 +0,0 @@
1
- /// <reference types="astro/client" />