Skip to content

Commit e971d84

Browse files
authored
repo sync
2 parents 288ac7b + c21a738 commit e971d84

49 files changed

Lines changed: 8314 additions & 24857 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/dry-run-sync-algolia-search-indices.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ jobs:
2121
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
2222
restore-keys: |
2323
${{ runner.os }}-node-
24-
- name: npm ci
24+
- name: Install dependencies
2525
run: npm ci
26+
- name: Run build scripts
27+
run: npm run build
2628
- name: (Dry run) sync indices
2729
env:
2830
ALGOLIA_APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID }}

.github/workflows/sync-algolia-search-indices.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ jobs:
2424
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
2525
restore-keys: |
2626
${{ runner.os }}-node-
27-
- name: npm ci
27+
- name: Install dependencies
2828
run: npm ci
29+
- name: Run build scripts
30+
run: npm run build
2931
- name: sync indices
3032
env:
3133
ALGOLIA_APPLICATION_ID: ${{ secrets.ALGOLIA_APPLICATION_ID }}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.algolia-cache
2+
.search-cache
23
.DS_Store
34
.env
45
/node_modules/

contributing/search.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,10 @@ Why do we need this? For our daily shipping needs, it's tolerable that search up
9090

9191
### Code files
9292

93-
- [javascripts/search.js](javascripts/search.js) - The browser-side code that enables search using Algolia's [InstantSearch.js](https://github.com/algolia/instantsearch.js/) library.
94-
- [lib/algolia/client.js](lib/algolia/client.js) - A thin wrapper around the [algoliasearch](https://ghub.io/algoliasearch) Node.js module for interacting with the Algolia API.
95-
- [lib/algolia/search-index.js](lib/algolia/search-index.js) - A class for generating structured search data from repository content and syncing it with the remote Algolia service. This class has built-in validation to ensure that all records are valid before they're uploaded. This class also takes care of removing deprecated records, and compares existing remote records with the latest local records to avoid uploading records that haven't changed.
96-
- [script/sync-algolia-search-indices.js](script/sync-algolia-search-indices.js) - The script used by the Actions workflow to update search indices on our Algolia account. This can also be [run in the development environment](#development).
93+
- [javascripts/search.js](javascripts/search.js) - The browser-side code that enables search.
94+
- [lib/search/algolia-client.js](lib/search/algolia-client.js) - A thin wrapper around the [algoliasearch](https://ghub.io/algoliasearch) Node.js module for interacting with the Algolia API.
95+
- [lib/search/algolia-search-index.js](lib/search/algolia-search-index.js) - A class for generating structured search data from repository content and syncing it with the remote Algolia service. This class has built-in validation to ensure that all records are valid before they're uploaded. This class also takes care of removing deprecated records, and compares existing remote records with the latest local records to avoid uploading records that haven't changed.
96+
- [script/sync-search-indices.js](script/sync-search-indices.js) - The script used by the Actions workflow to update search indices on our Algolia account. This can also be [run in the development environment](#development).
9797
- [tests/algolia-search.js](tests/algolia-search.js) - Tests!
9898

9999
## Indices
@@ -136,4 +136,4 @@ Each record represents a section of a page. Sections are derived by splitting up
136136
- It's not strictly necessary to set an `objectID` as Algolia will create one automatically, but by creating our own we have a guarantee that subsequent invocations of this upload script will overwrite existing records instead of creating numerous duplicate records with differing IDs.
137137
- Algolia has typo tolerance. Try spelling something wrong and see what you get!
138138
- Algolia has lots of controls for customizing each index, so we can add weights to certain attributes and create rules like "title is more important than body", etc. But it works pretty well as-is without any configuration.
139-
- Algolia has support for "advanced query syntax" for exact matching of quoted expressions and exclusion of words preceded by a `-` sign. This is off by default but we have it enabled in our browser client. This and many other settings can be configured in Algolia.com web interface. The settings in the web interface can be overridden by the InstantSearch.js client. See [javascripts/search.js]([javascripts/search.js).
139+
- Algolia has support for "advanced query syntax" for exact matching of quoted expressions and exclusion of words preceded by a `-` sign. This is off by default but we have it enabled in our browser client. This and many other settings can be configured in Algolia.com web interface. The settings in the web interface can be overridden by the search endpoint. See [middleware/search.js]([middleware/search.js).

includes/search-form.html

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
- On all other pages, in the header
66
-->
77

8-
<form class="mb-0" aria-hidden="true">
9-
<div id="search-input-container">
10-
<!-- Algolia instantsearch.js will add a search input here -->
11-
</div>
12-
</form>
8+
<div id="search-input-container" aria-hidden="true">
9+
<!-- will add a search input here -->
10+
</div>

javascripts/experiment.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import murmur from 'imurmurhash'
22
import { getUserEventsId, sendEvent } from './events'
3+
// import h from './hyperscript'
34

45
const TREATMENT = 'TREATMENT'
56
const CONTROL = 'CONTROL'
@@ -19,23 +20,6 @@ export async function sendSuccess (test) {
1920
})
2021
}
2122

22-
const xmlns = 'http://www.w3.org/2000/svg'
23-
24-
export function h (tagName, attributes = {}, children = []) {
25-
const el = ['svg', 'path'].includes(tagName)
26-
? document.createElementNS(xmlns, tagName)
27-
: document.createElement(tagName)
28-
Object.entries(attributes).forEach(
29-
([key, value]) => el.setAttribute(key, value)
30-
)
31-
children.forEach(child =>
32-
typeof child === 'string'
33-
? el.append(document.createTextNode(child))
34-
: el.append(child)
35-
)
36-
return el
37-
}
38-
3923
export default function () {
4024
// const testName = '$test-name$'
4125
// const xbucket = bucket(testName)

javascripts/fake-hogan.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

javascripts/hyperscript.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
const xmlns = 'http://www.w3.org/2000/svg'
2+
3+
const plainObjectConstructor = {}.constructor
4+
5+
function exists (value) {
6+
return value !== null && typeof value !== 'undefined'
7+
}
8+
9+
function isPlainObject (value) {
10+
return value.constructor === plainObjectConstructor
11+
}
12+
13+
function isString (value) {
14+
return typeof value === 'string'
15+
}
16+
17+
function renderChildren (el, children) {
18+
for (const child of children) {
19+
if (isPlainObject(child)) {
20+
Object.entries(child)
21+
.filter(([key, value]) => exists(value))
22+
.forEach(([key, value]) => el.setAttribute(key, value))
23+
} else if (Array.isArray(child)) {
24+
renderChildren(el, child)
25+
} else if (isString(child)) {
26+
el.append(document.createTextNode(child))
27+
} else {
28+
el.append(child)
29+
}
30+
}
31+
}
32+
33+
export default function h (tagName, ...children) {
34+
const el = ['svg', 'path'].includes(tagName)
35+
? document.createElementNS(xmlns, tagName)
36+
: document.createElement(tagName)
37+
renderChildren(el, children)
38+
return el
39+
}
40+
41+
export const tags = Object.fromEntries(
42+
['div', 'form', 'a', 'input', 'button', 'ol', 'li', 'em']
43+
.map(tagName => [tagName, (...args) => h(tagName, ...args)])
44+
)

0 commit comments

Comments
 (0)