@codecademy/brand 3.36.2-alpha.114f8c1aad.0 → 3.36.2-alpha.4249fc7d9c.0
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.
|
@@ -28,6 +28,9 @@ function getPortalOrigin() {
|
|
|
28
28
|
// for standard envs, use portal app in the same env
|
|
29
29
|
if (envs.some(s => `https://${s}.codecademy.com` === origin)) return origin;
|
|
30
30
|
|
|
31
|
+
// for PR envs (e.g. pr-40229-monolith.dev-eks.codecademy.com)
|
|
32
|
+
if (origin.includes('.dev-eks.codecademy.com')) return origin;
|
|
33
|
+
|
|
31
34
|
// for local, use local portal-app, replace if origin port is monolith or le
|
|
32
35
|
if (origin.includes('localhost')) return origin.replace(/:\d{4}/, ':3100');
|
|
33
36
|
|
|
@@ -102,11 +105,7 @@ export function serializeSearchWorkerSrc() {
|
|
|
102
105
|
* the worker via onmessage and passed back to the main thread via postMessage.
|
|
103
106
|
*/
|
|
104
107
|
function worker() {
|
|
105
|
-
const preloadTitlesPromise = (
|
|
106
|
-
const f = await fetch('{BASE_URL}/autocomplete-preload{SEARCH}');
|
|
107
|
-
const rawTitles = await f.json();
|
|
108
|
-
return rawTitles.map(preparseTitle);
|
|
109
|
-
})();
|
|
108
|
+
const preloadTitlesPromise = fetch('{BASE_URL}/autocomplete-preload{SEARCH}').then(f => f.json()).then(rawTitles => rawTitles.map(preparseTitle));
|
|
110
109
|
function preparseTitle({
|
|
111
110
|
value,
|
|
112
111
|
popularity
|
|
@@ -158,41 +157,43 @@ function worker() {
|
|
|
158
157
|
};
|
|
159
158
|
}
|
|
160
159
|
const maxResults = 5;
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
160
|
+
function autocompleteHandler(q) {
|
|
161
|
+
preloadTitlesPromise.then(titles => {
|
|
162
|
+
const scoredTitles = titles.map(t => getScoredTitle(q, t));
|
|
163
|
+
const topAutocompleteTitles = scoredTitles.filter(x => x.score > 0).sort((a, b) => a.score > b.score ? -1 : 1).slice(0, maxResults).map(t => ({
|
|
164
|
+
title: t.title,
|
|
165
|
+
segments: getHighlightSegments(t.title, t.charScores)
|
|
166
|
+
}));
|
|
167
|
+
postMessage({
|
|
168
|
+
query: q.query,
|
|
169
|
+
result: topAutocompleteTitles,
|
|
170
|
+
action: 'autocomplete'
|
|
171
|
+
});
|
|
172
172
|
});
|
|
173
173
|
}
|
|
174
|
-
|
|
175
|
-
|
|
174
|
+
function searchAsYouTypeHandler(q) {
|
|
175
|
+
fetch('{BASE_URL}/search-as-you-type{SEARCH}', {
|
|
176
176
|
body: JSON.stringify({
|
|
177
177
|
query: q.query,
|
|
178
178
|
max: maxResults
|
|
179
179
|
}),
|
|
180
180
|
method: 'POST'
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
181
|
+
}).then(f => f.json()).then(searchAsYouTypeResults => {
|
|
182
|
+
for (let i = 0; i < searchAsYouTypeResults.top.length; i++) {
|
|
183
|
+
const entry = searchAsYouTypeResults.top[i];
|
|
184
|
+
const t = preparseTitle({
|
|
185
|
+
value: entry.title,
|
|
186
|
+
popularity: 0
|
|
187
|
+
});
|
|
188
|
+
const charScores = getCharScores(q, t);
|
|
189
|
+
entry.segments = getHighlightSegments(entry.title, charScores);
|
|
190
|
+
entry.key = q.query + ':' + entry.title;
|
|
191
|
+
}
|
|
192
|
+
postMessage({
|
|
193
|
+
query: q.query,
|
|
194
|
+
result: searchAsYouTypeResults,
|
|
195
|
+
action: 'search-as-you-type'
|
|
187
196
|
});
|
|
188
|
-
const charScores = getCharScores(q, t);
|
|
189
|
-
entry.segments = getHighlightSegments(entry.title, charScores);
|
|
190
|
-
entry.key = q.query + ':' + entry.title;
|
|
191
|
-
}
|
|
192
|
-
postMessage({
|
|
193
|
-
query: q.query,
|
|
194
|
-
result: searchAsYouTypeResults,
|
|
195
|
-
action: 'search-as-you-type'
|
|
196
197
|
});
|
|
197
198
|
}
|
|
198
199
|
|
|
@@ -207,17 +208,17 @@ function worker() {
|
|
|
207
208
|
// Bonus scores are includes in certain cases
|
|
208
209
|
function getTotalScore(q, t, charScores) {
|
|
209
210
|
let fromChars = 0;
|
|
210
|
-
for (
|
|
211
|
-
fromChars +=
|
|
211
|
+
for (let i = 0; i < charScores.length; i++) {
|
|
212
|
+
fromChars += charScores[i];
|
|
212
213
|
}
|
|
213
214
|
const fromPopularity = (t.popularity || 0) * popularityStrength;
|
|
214
215
|
let bonus = 0;
|
|
215
216
|
// for each complete word present in both the title and query
|
|
216
|
-
|
|
217
|
+
q.words.forEach(qw => {
|
|
217
218
|
if (t.words.has(qw)) {
|
|
218
219
|
bonus += 100;
|
|
219
220
|
}
|
|
220
|
-
}
|
|
221
|
+
});
|
|
221
222
|
|
|
222
223
|
// if the title starts with the query
|
|
223
224
|
if (t.lower.startsWith(q.query)) {
|
|
@@ -341,9 +342,11 @@ function worker() {
|
|
|
341
342
|
// "authentication" or other words ending in "ion"
|
|
342
343
|
const minMatchLength = Math.ceil(avgQueryWordLength ** 0.65);
|
|
343
344
|
const charScores = [];
|
|
344
|
-
for (
|
|
345
|
+
for (let i = 0; i < cmcsForTitleChars.length; i++) {
|
|
346
|
+
const cmcs = cmcsForTitleChars[i];
|
|
345
347
|
let score = 0;
|
|
346
|
-
for (
|
|
348
|
+
for (let j = 0; j < cmcs.length; j++) {
|
|
349
|
+
const cmc = cmcs[j];
|
|
347
350
|
// if the string of consecutive matching chars meets the minMatchLength
|
|
348
351
|
// or if it's a standalone word in the query (e.g "C")
|
|
349
352
|
if (cmc.value.length >= minMatchLength || q.words.has(cmc.value)) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codecademy/brand",
|
|
3
3
|
"description": "Brand component library for Codecademy",
|
|
4
|
-
"version": "3.36.2-alpha.
|
|
4
|
+
"version": "3.36.2-alpha.4249fc7d9c.0",
|
|
5
5
|
"author": "Codecademy Engineering <dev@codecademy.com>",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@emotion/is-prop-valid": "^1.2.1",
|