--- /dev/null
+<template>
+ <div id="docsearch"></div>
+</template>
+
+<script lang="ts">
+import { AlgoliaSearchOptions } from 'algoliasearch'
+// import docsearch from '@docsearch/js'
+// import '@docsearch/css'
+import { useRoute, useRouter } from 'vitepress'
+import { getCurrentInstance, onMounted, PropType, watch } from 'vue'
+
+function isSpecialClick(event: MouseEvent) {
+ return (
+ event.button === 1 ||
+ event.altKey ||
+ event.ctrlKey ||
+ event.metaKey ||
+ event.shiftKey
+ )
+}
+
+function getRelativePath(absoluteUrl: string) {
+ const { pathname, hash } = new URL(absoluteUrl)
+ // const url = pathname.replace(this.$site.base, '/') + hash
+ const url = pathname + hash
+
+ return url
+}
+
+export default {
+ name: 'AlgoliaSearchBox',
+
+ props: {
+ options: {
+ type: Object as PropType<AlgoliaSearchOptions>,
+ required: true,
+ },
+ },
+
+ setup(props) {
+ const route = useRoute()
+ const router = useRouter()
+ const vm = getCurrentInstance()
+
+ watch(
+ () => props.options,
+ newValue => {
+ update(newValue)
+ }
+ )
+
+ function update(options: any) {
+ if (vm && vm.vnode.el) {
+ vm.vnode.el.innerHTML = '<div id="docsearch"></div>'
+ initialize(options)
+ }
+ }
+
+ function initialize(userOptions: any) {
+ Promise.all([
+ import('@docsearch/js'),
+ import('@docsearch/css'),
+ // import(/* webpackChunkName: "docsearch" */ '@docsearch/js'),
+ // Promise.resolve(docsearch),
+ // import(/* webpackChunkName: "docsearch" */ '@docsearch/css'),
+ ]).then(([docsearch]) => {
+ docsearch = docsearch.default
+
+ docsearch(
+ Object.assign({}, userOptions, {
+ container: '#docsearch',
+ // #697 Make DocSearch work well in i18n mode.
+ searchParameters: Object.assign(
+ {},
+ // lang && {
+ // facetFilters: [`lang:${lang}`].concat(
+ // userOptions.facetFilters || []
+ // )
+ // },
+ userOptions.searchParameters
+ ),
+ navigator: {
+ navigate: ({ suggestionUrl }: { suggestionUrl: string }) => {
+ const { pathname: hitPathname } = new URL(
+ window.location.origin + suggestionUrl
+ )
+
+ // Vue Router doesn't handle same-page navigation so we use
+ // the native browser location API for anchor navigation.
+ if (route.path === hitPathname) {
+ window.location.assign(window.location.origin + suggestionUrl)
+ } else {
+ router.go(suggestionUrl)
+ }
+ },
+ },
+ transformItems: items => {
+ return items.map(item => {
+ return Object.assign({}, item, {
+ url: getRelativePath(item.url),
+ })
+ })
+ },
+ hitComponent: ({ hit, children }) => {
+ const relativeHit = hit.url.startsWith('http')
+ ? getRelativePath(hit.url as string)
+ : hit.url
+
+ return {
+ type: 'a',
+ ref: undefined,
+ constructor: undefined,
+ key: undefined,
+ props: {
+ href: hit.url,
+ onClick: (event: MouseEvent) => {
+ if (isSpecialClick(event)) {
+ return
+ }
+
+ // We rely on the native link scrolling when user is
+ // already on the right anchor because Vue Router doesn't
+ // support duplicated history entries.
+ if (route.path === relativeHit) {
+ return
+ }
+
+ // If the hits goes to another page, we prevent the native link behavior
+ // to leverage the Vue Router loading feature.
+ if (route.path !== relativeHit) {
+ event.preventDefault()
+ }
+
+ router.go(relativeHit)
+ },
+ children,
+ },
+ }
+ },
+ })
+ )
+ })
+ }
+
+ onMounted(() => {
+ initialize(props.options)
+ })
+ },
+}
+</script>
+
+<style>
+.DocSearch {
+ --docsearch-primary-color: #42b983;
+ --docsearch-highlight-color: var(--docsearch-primary-color);
+ --docsearch-searchbox-shadow: inset 0 0 0 2px var(--docsearch-primary-color);
+}
+</style>
# yarn lockfile v1
+"@algolia/cache-browser-local-storage@4.5.1":
+ version "4.5.1"
+ resolved "https://registry.yarnpkg.com/@algolia/cache-browser-local-storage/-/cache-browser-local-storage-4.5.1.tgz#bdf58c30795683fd48310c552c3a10f10fb26e2b"
+ integrity sha512-TAQHRHaCUAR0bNhUHG0CnO6FTx3EMPwZQrjPuNS6kHvCQ/H8dVD0sLsHyM8C7U4j33xPQCWi9TBnSx8cYXNmNw==
+ dependencies:
+ "@algolia/cache-common" "4.5.1"
+
+"@algolia/cache-common@4.5.1":
+ version "4.5.1"
+ resolved "https://registry.yarnpkg.com/@algolia/cache-common/-/cache-common-4.5.1.tgz#3aefda3382dc30b67091b01a3d7461d937082821"
+ integrity sha512-Sux+pcedQi9sfScIiQdl6pEaTVl712qM9OblvDhnaeF1v6lf4jyTlRTiBLP7YBLuvO1Yo54W3maf03kmz9PVhA==
+
+"@algolia/cache-in-memory@4.5.1":
+ version "4.5.1"
+ resolved "https://registry.yarnpkg.com/@algolia/cache-in-memory/-/cache-in-memory-4.5.1.tgz#127cd473474f62300a157f4ee3b3f6836003cf35"
+ integrity sha512-fzwAtBFwveuG+E5T/namChEIvdVl0DoV3djV1C078b/JpO5+DeAwuXIJGYbyl950u170n5NEYuIwYG+R6h4lJQ==
+ dependencies:
+ "@algolia/cache-common" "4.5.1"
+
+"@algolia/client-account@4.5.1":
+ version "4.5.1"
+ resolved "https://registry.yarnpkg.com/@algolia/client-account/-/client-account-4.5.1.tgz#7d3ccda09d3c7849b171c915da0833e7649bab33"
+ integrity sha512-2WFEaI7Zf4ljnBsSAS4e+YylZ5glovm78xFg4E1JKA8PE6M+TeIgUY6HO2ouLh2dqQKxc9UfdAT1Loo/dha2iQ==
+ dependencies:
+ "@algolia/client-common" "4.5.1"
+ "@algolia/client-search" "4.5.1"
+ "@algolia/transporter" "4.5.1"
+
+"@algolia/client-analytics@4.5.1":
+ version "4.5.1"
+ resolved "https://registry.yarnpkg.com/@algolia/client-analytics/-/client-analytics-4.5.1.tgz#bfc2a7292a9ea789ca3c99f79b1f96c08d378828"
+ integrity sha512-bTmZUU8zhZMWBeGEQ/TVqLoL3OOT0benU0HtS3iOnQURwb+AOCv3RsgZvkj2djp+M24Q6P8/L34uBJMmCurbLg==
+ dependencies:
+ "@algolia/client-common" "4.5.1"
+ "@algolia/client-search" "4.5.1"
+ "@algolia/requester-common" "4.5.1"
+ "@algolia/transporter" "4.5.1"
+
+"@algolia/client-common@4.5.1":
+ version "4.5.1"
+ resolved "https://registry.yarnpkg.com/@algolia/client-common/-/client-common-4.5.1.tgz#91a401eba6eafd7cc74a0aeccb4c6e6cb1e72026"
+ integrity sha512-5CpIf8IK1hke7q+N4e+A4TWdFXVJ5Qwyaa0xS84DrDO8HQ7vfYbDvG1oYa9hVEtGn6c3WVKPAvuWynK+fXQQCA==
+ dependencies:
+ "@algolia/requester-common" "4.5.1"
+ "@algolia/transporter" "4.5.1"
+
+"@algolia/client-recommendation@4.5.1":
+ version "4.5.1"
+ resolved "https://registry.yarnpkg.com/@algolia/client-recommendation/-/client-recommendation-4.5.1.tgz#57a1fe30987c90b10d5119b8e7d6cd91c423e54c"
+ integrity sha512-GiFrNSImoEBUQICjFBEoxPGzrjWji8PY9GeMg2CNvOYcRQ0Xt0Y36v9GN53NLjvB7QdQ2FlE1Cuv/PLUfS/aQQ==
+ dependencies:
+ "@algolia/client-common" "4.5.1"
+ "@algolia/requester-common" "4.5.1"
+ "@algolia/transporter" "4.5.1"
+
+"@algolia/client-search@4.5.1":
+ version "4.5.1"
+ resolved "https://registry.yarnpkg.com/@algolia/client-search/-/client-search-4.5.1.tgz#cb798c99d6621e29a36334b92205518a74ecdf3e"
+ integrity sha512-wjuOTte9Auo9Cg4fL0709PjeJ9rXFh4okYUrOt/2SWqQid6DSdZOp+BtyaHKV3E94sj+SlmMxkMUacYluYg5zA==
+ dependencies:
+ "@algolia/client-common" "4.5.1"
+ "@algolia/requester-common" "4.5.1"
+ "@algolia/transporter" "4.5.1"
+
+"@algolia/logger-common@4.5.1":
+ version "4.5.1"
+ resolved "https://registry.yarnpkg.com/@algolia/logger-common/-/logger-common-4.5.1.tgz#18d654516369a28e25ad7eee4fc2882fd47ed8ec"
+ integrity sha512-ZoVnGriinlLHlkvn5K7djOUn1/1IeTjU8rDzOJ3t06T+2hQytgJghaX7rSwKIeH4CjWMy61w8jLisuGJRBOEeg==
+
+"@algolia/logger-console@4.5.1":
+ version "4.5.1"
+ resolved "https://registry.yarnpkg.com/@algolia/logger-console/-/logger-console-4.5.1.tgz#c9def97c20bea5eecb4b07f8d3f733c0192d1761"
+ integrity sha512-1qa7K18+uAgxyWuguayaDS5ViiZFcOjI3J5ACBb0i/n7RsXUo149lP6mwmx6TIU7s135hT0f0TCqnvfMvN1ilA==
+ dependencies:
+ "@algolia/logger-common" "4.5.1"
+
+"@algolia/requester-browser-xhr@4.5.1":
+ version "4.5.1"
+ resolved "https://registry.yarnpkg.com/@algolia/requester-browser-xhr/-/requester-browser-xhr-4.5.1.tgz#838b55209d2c83572df261338f7cd75be36de401"
+ integrity sha512-tsQz+9pZw9dwPm/wMvZDpsWFZgmghLjXi4c3O4rfwoP/Ikum5fhle5fiR14yb4Lw4WlOQ1AJIHJvrg1qLIG8hQ==
+ dependencies:
+ "@algolia/requester-common" "4.5.1"
+
+"@algolia/requester-common@4.5.1":
+ version "4.5.1"
+ resolved "https://registry.yarnpkg.com/@algolia/requester-common/-/requester-common-4.5.1.tgz#a34d02daa6093e112b528d3bcd5a5467c00ba823"
+ integrity sha512-bPCiLvhHKXaka7f5FLtheChToz0yHVhvza64naFJRRh/3kC0nvyrvQ0ogjiydiSrGIfdNDyyTVfKGdk4gS5gyA==
+
+"@algolia/requester-node-http@4.5.1":
+ version "4.5.1"
+ resolved "https://registry.yarnpkg.com/@algolia/requester-node-http/-/requester-node-http-4.5.1.tgz#29911c104c6714a5cb29d3991f2b50c52301e091"
+ integrity sha512-BfFc2h9eQOKu1gGs3DtQO7GrVZW/rxUgpJVLja4UVQyGplJyTCrFgkTyfl+8rb3MkNgA/S2LNo7cKNSPfpqeAQ==
+ dependencies:
+ "@algolia/requester-common" "4.5.1"
+
+"@algolia/transporter@4.5.1":
+ version "4.5.1"
+ resolved "https://registry.yarnpkg.com/@algolia/transporter/-/transporter-4.5.1.tgz#e0a5c64f358b6751f867001f51f384d6fc7ede14"
+ integrity sha512-asPDNToDAPhH0tM6qKGTn1l0wTlNUbekpa1ifZ6v+qhSjo3VdqGyp+2VeciJOBW/wVHXh3HUbAcycvLERRlCLg==
+ dependencies:
+ "@algolia/cache-common" "4.5.1"
+ "@algolia/logger-common" "4.5.1"
+ "@algolia/requester-common" "4.5.1"
+
"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.5.5":
version "7.10.4"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.10.4.tgz#168da1a36e90da68ae8d49c0f1b48c7c6249213a"
exec-sh "^0.3.2"
minimist "^1.2.0"
+"@docsearch/css@^1.0.0-alpha.27", "@docsearch/css@^1.0.0-alpha.28":
+ version "1.0.0-alpha.28"
+ resolved "https://registry.yarnpkg.com/@docsearch/css/-/css-1.0.0-alpha.28.tgz#c8a2cd8c1bb3a6855c51892e9dbdab5d42fe6e23"
+ integrity sha512-1AhRzVdAkrWwhaxTX6/R7SnFHz8yLz1W8I/AldlTrfbNvZs9INk1FZiEFTJdgHaP68nhgQNWSGlQiDiI3y2RYg==
+
+"@docsearch/js@^1.0.0-alpha.27":
+ version "1.0.0-alpha.28"
+ resolved "https://registry.yarnpkg.com/@docsearch/js/-/js-1.0.0-alpha.28.tgz#f0fde7b8a6b1e1d8a7ae1e7655c43d959b457b2b"
+ integrity sha512-2g7aPhBy7FoEyeZW2G3LYHWVa8CFvqyozEz8PXt3hyywdFcmEIqmoCRwn8kboVftrOKCjtPcuLCewsaBoB3uiw==
+ dependencies:
+ "@docsearch/react" "^1.0.0-alpha.28"
+ preact "^10.0.0"
+
+"@docsearch/react@^1.0.0-alpha.28":
+ version "1.0.0-alpha.28"
+ resolved "https://registry.yarnpkg.com/@docsearch/react/-/react-1.0.0-alpha.28.tgz#4f039ed79f8b3332b19a57677b219aebc5010e9d"
+ integrity sha512-XjJOnCBXn+UZmtuDmgzlVIHnnvh6yHVwG4aFq8AXN6xJEIX3f180FvGaowFWAxgdtHplJxFGux0Xx4piHqBzIw==
+ dependencies:
+ "@docsearch/css" "^1.0.0-alpha.28"
+ "@francoischalifour/autocomplete-core" "^1.0.0-alpha.28"
+ "@francoischalifour/autocomplete-preset-algolia" "^1.0.0-alpha.28"
+ algoliasearch "^4.0.0"
+
+"@francoischalifour/autocomplete-core@^1.0.0-alpha.28":
+ 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.28":
+ 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==
+
"@istanbuljs/load-nyc-config@^1.0.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz#fd3db1d59ecf7cf121e80650bb86712f9b55eced"
json-schema-traverse "^0.4.1"
uri-js "^4.2.2"
+algoliasearch@^4.0.0, algoliasearch@^4.5.1:
+ version "4.5.1"
+ resolved "https://registry.yarnpkg.com/algoliasearch/-/algoliasearch-4.5.1.tgz#fd20cd76f6ba3fbecdd4e11bdaefefb44abc0b38"
+ integrity sha512-b6yT1vWMlBdVObQipKxvt0M6SEvGetVj+FFFlo0Fy06gkdj6WCJaS4t10Q/hC3I2VG9QmpCqlK3Esgg1y1E+uw==
+ dependencies:
+ "@algolia/cache-browser-local-storage" "4.5.1"
+ "@algolia/cache-common" "4.5.1"
+ "@algolia/cache-in-memory" "4.5.1"
+ "@algolia/client-account" "4.5.1"
+ "@algolia/client-analytics" "4.5.1"
+ "@algolia/client-common" "4.5.1"
+ "@algolia/client-recommendation" "4.5.1"
+ "@algolia/client-search" "4.5.1"
+ "@algolia/logger-common" "4.5.1"
+ "@algolia/logger-console" "4.5.1"
+ "@algolia/requester-browser-xhr" "4.5.1"
+ "@algolia/requester-common" "4.5.1"
+ "@algolia/requester-node-http" "4.5.1"
+ "@algolia/transporter" "4.5.1"
+
ansi-colors@3.2.3:
version "3.2.3"
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-3.2.3.tgz#57d35b8686e851e2cc04c403f1c00203976a1813"
nanoid "^3.1.12"
source-map "^0.6.1"
+preact@^10.0.0:
+ version "10.5.4"
+ resolved "https://registry.yarnpkg.com/preact/-/preact-10.5.4.tgz#1e4d148f949fa54656df6c9bc9218bd4e12016e3"
+ integrity sha512-u0LnVtL9WWF61RLzIbEsVFOdsahoTQkQqeRwyf4eWuLMFrxTH/C47tqcnizbUH54E4KG8UzuuZaMc9KarHmpqQ==
+
prelude-ls@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
vue "^3.0.0-rc.5"
ws "^7.2.3"
-vitepress@^0.6.0:
- version "0.6.0"
- resolved "https://registry.yarnpkg.com/vitepress/-/vitepress-0.6.0.tgz#805bd529a21ceccc2b43da5a7be0c4e526512a91"
- integrity sha512-+bkHmRx5QjbdU0rBxbJtBffESQk9CwPoRjtlqcYX1jozurCX/09oAik6tHP5+Hzoz4DMPCVgTG9jnjFjGi1wug==
+vitepress@^0.7.0:
+ version "0.7.0"
+ resolved "https://registry.yarnpkg.com/vitepress/-/vitepress-0.7.0.tgz#08b9867c23282471baccfbab27128e613532639e"
+ integrity sha512-mcYN0rz9uR5XRnJKyxdOw2tir3jJZQ3nJ/vb23YCV98utnPSxTFUZ33Th7N7XCj2bh1Q3JjodU220W8w3kH+tA==
dependencies:
"@vue/compiler-sfc" "^3.0.0-rc.11"
"@vue/server-renderer" "^3.0.0-rc.11"