docs(nxdev): update algolia docsearch version (#9614)

This commit is contained in:
Benjamin Cabanes 2022-03-30 14:50:22 -04:00 committed by GitHub
parent e22bdd01c2
commit 42f1c7384a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 30 deletions

View File

@ -9,10 +9,9 @@ import { createPortal } from 'react-dom';
const ACTION_KEY_DEFAULT = ['Ctrl ', 'Control']; const ACTION_KEY_DEFAULT = ['Ctrl ', 'Control'];
const ACTION_KEY_APPLE = ['⌘', 'Command']; const ACTION_KEY_APPLE = ['⌘', 'Command'];
// TODO@ben: remove replace pattern when Algolia is updated
function Hit({ hit, children }) { function Hit({ hit, children }) {
return ( return (
<Link href={hit.url.replace(/\/(p|l)\/(a|r|n)/, '')}> <Link href={hit.url}>
<a>{children}</a> <a>{children}</a>
</Link> </Link>
); );
@ -22,7 +21,7 @@ export function AlgoliaSearch() {
const router = useRouter(); const router = useRouter();
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const searchButtonRef = useRef<HTMLButtonElement>(null); const searchButtonRef = useRef<HTMLButtonElement>(null);
const [initialQuery, setInitialQuery] = useState(null); const [initialQuery, setInitialQuery] = useState('');
const [browserDetected, setBrowserDetected] = useState(false); const [browserDetected, setBrowserDetected] = useState(false);
const [actionKey, setActionKey] = useState(ACTION_KEY_DEFAULT); const [actionKey, setActionKey] = useState(ACTION_KEY_DEFAULT);
@ -97,28 +96,37 @@ export function AlgoliaSearch() {
{isOpen && {isOpen &&
createPortal( createPortal(
<DocSearchModal <DocSearchModal
// searchParameters={{
// facetFilters: ['language:en'],
// }}
initialQuery={initialQuery} initialQuery={initialQuery}
placeholder="Search documentation"
initialScrollY={window.scrollY} initialScrollY={window.scrollY}
onClose={handleClose} onClose={handleClose}
indexName="nx" indexName="nx"
apiKey="0c9c3fb22624056e7475eddcbcbfbe91" apiKey="0c9c3fb22624056e7475eddcbcbfbe91"
appId="BH4D9OD16A" appId="BH4D9OD16A"
navigator={{ navigator={{
navigate({ suggestionUrl }) { navigate({ itemUrl }) {
setIsOpen(false); setIsOpen(false);
router.push(suggestionUrl); router.push(itemUrl);
}, },
}} }}
hitComponent={Hit} hitComponent={Hit}
transformItems={(items) => { transformItems={(items) => {
return items.map((item) => { return items.map((item, index) => {
// We transform the absolute URL into a relative URL to
// leverage Next's preloading.
const a = document.createElement('a'); const a = document.createElement('a');
a.href = item.url; a.href = item.url;
const hash = a.hash === '#content-wrapper' ? '' : a.hash; const hash = a.hash === '#content-wrapper' ? '' : a.hash;
if (item.hierarchy?.lvl0) {
item.hierarchy.lvl0 = item.hierarchy.lvl0.replace(
/&amp;/g,
'&'
);
}
return { return {
...item, ...item,
url: `${a.pathname}${hash}`, url: `${a.pathname}${hash}`,

View File

@ -269,7 +269,7 @@
} }
}, },
"dependencies": { "dependencies": {
"@docsearch/react": "1.0.0-alpha.27", "@docsearch/react": "3.0.0",
"@headlessui/react": "^1.1.1", "@headlessui/react": "^1.1.1",
"@heroicons/react": "^1.0.1", "@heroicons/react": "^1.0.1",
"@monaco-editor/react": "^4.3.1", "@monaco-editor/react": "^4.3.1",

View File

@ -2,6 +2,25 @@
# yarn lockfile v1 # yarn lockfile v1
"@algolia/autocomplete-core@1.5.2":
version "1.5.2"
resolved "https://registry.yarnpkg.com/@algolia/autocomplete-core/-/autocomplete-core-1.5.2.tgz#ec0178e07b44fd74a057728ac157291b26cecf37"
integrity sha512-DY0bhyczFSS1b/CqJlTE/nQRtnTAHl6IemIkBy0nEWnhDzRDdtdx4p5Uuk3vwAFxwEEgi1WqKwgSSMx6DpNL4A==
dependencies:
"@algolia/autocomplete-shared" "1.5.2"
"@algolia/autocomplete-preset-algolia@1.5.2":
version "1.5.2"
resolved "https://registry.yarnpkg.com/@algolia/autocomplete-preset-algolia/-/autocomplete-preset-algolia-1.5.2.tgz#36c5638cc6dba6ea46a86e5a0314637ca40a77ca"
integrity sha512-3MRYnYQFJyovANzSX2CToS6/5cfVjbLLqFsZTKcvF3abhQzxbqwwaMBlJtt620uBUOeMzhdfasKhCc40+RHiZw==
dependencies:
"@algolia/autocomplete-shared" "1.5.2"
"@algolia/autocomplete-shared@1.5.2":
version "1.5.2"
resolved "https://registry.yarnpkg.com/@algolia/autocomplete-shared/-/autocomplete-shared-1.5.2.tgz#e157f9ad624ab8fd940ff28bd2094cdf199cdd79"
integrity sha512-ylQAYv5H0YKMfHgVWX0j0NmL8XBcAeeeVQUmppnnMtzDbDnca6CzhKj3Q8eF9cHCgcdTDdb5K+3aKyGWA0obug==
"@algolia/cache-browser-local-storage@4.13.0": "@algolia/cache-browser-local-storage@4.13.0":
version "4.13.0" version "4.13.0"
resolved "https://registry.yarnpkg.com/@algolia/cache-browser-local-storage/-/cache-browser-local-storage-4.13.0.tgz#f8aa4fe31104b19d616ea392f9ed5c2ea847d964" resolved "https://registry.yarnpkg.com/@algolia/cache-browser-local-storage/-/cache-browser-local-storage-4.13.0.tgz#f8aa4fe31104b19d616ea392f9ed5c2ea847d964"
@ -1804,19 +1823,19 @@
resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz#1d572bfbbe14b7704e0ba0f39b74815b84870d70" resolved "https://registry.yarnpkg.com/@discoveryjs/json-ext/-/json-ext-0.5.7.tgz#1d572bfbbe14b7704e0ba0f39b74815b84870d70"
integrity sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw== integrity sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw==
"@docsearch/css@^1.0.0-alpha.27": "@docsearch/css@3.0.0":
version "1.0.0-alpha.28" version "3.0.0"
resolved "https://registry.yarnpkg.com/@docsearch/css/-/css-1.0.0-alpha.28.tgz#c8a2cd8c1bb3a6855c51892e9dbdab5d42fe6e23" resolved "https://registry.yarnpkg.com/@docsearch/css/-/css-3.0.0.tgz#fe57b474802ffd706d3246eab25d52fac8aa3698"
integrity sha512-1AhRzVdAkrWwhaxTX6/R7SnFHz8yLz1W8I/AldlTrfbNvZs9INk1FZiEFTJdgHaP68nhgQNWSGlQiDiI3y2RYg== integrity sha512-1kkV7tkAsiuEd0shunYRByKJe3xQDG2q7wYg24SOw1nV9/2lwEd4WrUYRJC/ukGTl2/kHeFxsaUvtiOy0y6fFA==
"@docsearch/react@1.0.0-alpha.27": "@docsearch/react@3.0.0":
version "1.0.0-alpha.27" version "3.0.0"
resolved "https://registry.yarnpkg.com/@docsearch/react/-/react-1.0.0-alpha.27.tgz#eae61d648ddc3667c5dee82c4cd9d47bf35a3c85" resolved "https://registry.yarnpkg.com/@docsearch/react/-/react-3.0.0.tgz#d02ebdc67573412185a6a4df13bc254c7c0da491"
integrity sha512-jcgUHZsrNNRsaVsplqKhXWheh4VzRTCdhsPuVhJMRvfsFUqXEPo/7kVt5xIybtOj9u+/FVdeSO+APJEE2rakYA== integrity sha512-yhMacqS6TVQYoBh/o603zszIb5Bl8MIXuOc6Vy617I74pirisDzzcNh0NEaYQt50fVVR3khUbeEhUEWEWipESg==
dependencies: dependencies:
"@docsearch/css" "^1.0.0-alpha.27" "@algolia/autocomplete-core" "1.5.2"
"@francoischalifour/autocomplete-core" "^1.0.0-alpha.27" "@algolia/autocomplete-preset-algolia" "1.5.2"
"@francoischalifour/autocomplete-preset-algolia" "^1.0.0-alpha.27" "@docsearch/css" "3.0.0"
algoliasearch "^4.0.0" algoliasearch "^4.0.0"
"@emotion/cache@^10.0.27", "@emotion/cache@^10.0.9": "@emotion/cache@^10.0.27", "@emotion/cache@^10.0.9":
@ -1936,16 +1955,6 @@
minimatch "^3.0.4" minimatch "^3.0.4"
strip-json-comments "^3.1.1" strip-json-comments "^3.1.1"
"@francoischalifour/autocomplete-core@^1.0.0-alpha.27":
version "1.0.0-alpha.28"
resolved "https://registry.yarnpkg.com/@francoischalifour/autocomplete-core/-/autocomplete-core-1.0.0-alpha.28.tgz#6b9d8491288e77f831e9b345d461623b0d3f5005"
integrity sha512-rL9x+72btViw+9icfBKUJjZj87FgjFrD2esuTUqtj4RAX3s4AuVZiN8XEsfjQBSc6qJk31cxlvqZHC/BIyYXgg==
"@francoischalifour/autocomplete-preset-algolia@^1.0.0-alpha.27":
version "1.0.0-alpha.28"
resolved "https://registry.yarnpkg.com/@francoischalifour/autocomplete-preset-algolia/-/autocomplete-preset-algolia-1.0.0-alpha.28.tgz#a5ad7996f42e43e4acbb4e0010d663746d0e9997"
integrity sha512-bprfNmYt1opFUFEtD2XfY/kEsm13bzHQgU80uMjhuK0DJ914IjolT1GytpkdM6tJ4MBvyiJPP+bTtWO+BZ7c7w==
"@gar/promisify@^1.0.1", "@gar/promisify@^1.1.3": "@gar/promisify@^1.0.1", "@gar/promisify@^1.1.3":
version "1.1.3" version "1.1.3"
resolved "https://registry.yarnpkg.com/@gar/promisify/-/promisify-1.1.3.tgz#555193ab2e3bb3b6adc3d551c9c030d9e860daf6" resolved "https://registry.yarnpkg.com/@gar/promisify/-/promisify-1.1.3.tgz#555193ab2e3bb3b6adc3d551c9c030d9e860daf6"