forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move site search to use an endpoint (github#17359)
* Move site search to use an endpoint * Update browser.js * Update search.js * Update lib/search/versions.js Co-authored-by: James M. Greene <[email protected]> * Fix URLs Co-authored-by: James M. Greene <[email protected]>
- Loading branch information
1 parent
c5c2347
commit 2fb2e96
Showing
30 changed files
with
436 additions
and
416 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.algolia-cache | ||
.search-cache | ||
.DS_Store | ||
.env | ||
/node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const xmlns = 'http://www.w3.org/2000/svg' | ||
|
||
const plainObjectConstructor = {}.constructor | ||
|
||
function exists (value) { | ||
return value !== null && typeof value !== 'undefined' | ||
} | ||
|
||
function isPlainObject (value) { | ||
return value.constructor === plainObjectConstructor | ||
} | ||
|
||
function isString (value) { | ||
return typeof value === 'string' | ||
} | ||
|
||
function renderChildren (el, children) { | ||
for (const child of children) { | ||
if (isPlainObject(child)) { | ||
Object.entries(child) | ||
.filter(([key, value]) => exists(value)) | ||
.forEach(([key, value]) => el.setAttribute(key, value)) | ||
} else if (Array.isArray(child)) { | ||
renderChildren(el, child) | ||
} else if (isString(child)) { | ||
el.append(document.createTextNode(child)) | ||
} else { | ||
el.append(child) | ||
} | ||
} | ||
} | ||
|
||
export default function h (tagName, ...children) { | ||
const el = ['svg', 'path'].includes(tagName) | ||
? document.createElementNS(xmlns, tagName) | ||
: document.createElement(tagName) | ||
renderChildren(el, children) | ||
return el | ||
} | ||
|
||
export const tags = Object.fromEntries( | ||
['div', 'form', 'a', 'input', 'button', 'ol', 'li', 'em'] | ||
.map(tagName => [tagName, (...args) => h(tagName, ...args)]) | ||
) |
Oops, something went wrong.