提交 71c5f246 编写于 作者: D DCloud_LXH

feat: use algolia docsearch 3.x

上级 30622da5
<template>
<div id="docsearch"></div>
</template>
<script>
import '@docsearch/css';
const resolveRoutePathFromUrl = (url, base = '/') =>
url
// remove url origin
.replace(/^(https?:)?\/\/[^/]*/, '')
// remove site base
.replace(new RegExp(`^${base}`), '/');
const loadDocsearch = async () => {
const docsearch = await import('@docsearch/js');
return docsearch.default;
};
export default {
name: 'AlgoliaSearchBox',
props: ['options'],
watch: {
$lang(newValue) {
this.update(this.options, newValue);
},
options(newValue) {
this.update(newValue, this.$lang);
},
},
mounted() {
this.initialize(this.options, this.$lang);
},
methods: {
initialize(userOptions, lang) {
loadDocsearch().then(docsearch => {
const { algoliaOptions = {} } = userOptions;
docsearch(
Object.assign({}, userOptions, {
container: '#docsearch',
// #697 Make docsearch work well at i18n mode.
searchParameters: {
...algoliaOptions,
facetFilters: [`lang:${lang}`].concat(algoliaOptions.facetFilters || []),
},
navigator: {
// when pressing Enter without metaKey
navigate: ({ itemUrl }) => {
this.$router.push(itemUrl);
},
},
// transform full url to route path
transformItems: items =>
items.map(item => {
// the `item.url` is full url with protocol and hostname
// so we have to transform it to vue-router path
return {
...item,
url: resolveRoutePathFromUrl(item.url, this.$site.base),
};
}),
// handle `onClick` by `this.$routerpush`
/* hitComponent: ({ hit, children }) => {
const vnode = createElement(
'a',
{
href: hit.url,
onClick: event => {
if (isSpecialClick(event)) {
return;
}
event.preventDefault();
this.$router.push(hit.url);
},
},
children
);
console.log('vnode :>> ', vnode);
console.log('children :>> ', children);
return vnode;
}, */
})
);
});
},
update(options, lang) {
this.$el.innerHTML = '<div id="docsearch"></div>';
this.initialize(options, lang);
},
},
};
</script>
<style lang="stylus">
.DocSearch
--docsearch-primary-color $accentColor
--docsearch-highlight-color var(--docsearch-primary-color)
--docsearch-searchbox-shadow inset 0 0 0 2px var(--docsearch-primary-color)
#docsearch
display flex
flex-direction column
justify-content center
#docsearch span
@media (min-width: $MQMobile)
&
display flex
@media (max-width: $MQMobile)
:root
--docsearch-spacing 10px
--docsearch-footer-height 40px
.DocSearch-Button-Keys,.DocSearch-Button-Key,.DocSearch-Button-KeySeparator,.DocSearch-Button-Placeholder
display none !important
.DocSearch-Search-Icon
vertical-align middle
.DocSearch-Dropdown
height 100%
.DocSearch-Container
height 100vh
height -webkit-fill-available
position absolute
.DocSearch-Footer
border-radius 0
bottom 0
position absolute
.DocSearch-Hit-content-wrapper
display flex
position relative
width 80%
.DocSearch-Modal
border-radius 0
box-shadow none
height 100vh
height -webkit-fill-available
margin 0
max-width 100%
width 100%
.DocSearch-Cancel
-webkit-appearance none
-moz-appearance none
appearance none
background none
border 0
color var(--docsearch-highlight-color)
cursor pointer
display inline-block
flex none
font inherit
font-size 1em
font-weight 500
margin-left var(--docsearch-spacing)
outline none
overflow hidden
padding 0
-webkit-user-select none
-moz-user-select none
-ms-user-select none
user-select none
white-space nowrap
.DocSearch-Commands,.DocSearch-Hit-Tree
display none
</style>
......@@ -77,7 +77,7 @@
</template>
<script>
import AlgoliaSearchBox from '@AlgoliaSearchBox'
import AlgoliaSearchBox from './AlgoliaSearchBox'
import SearchBox from './SearchBox'
import SidebarButton from '@theme/components/SidebarButton.vue'
import NavLinks from '@theme/components/NavLinks.vue'
......
......@@ -26,5 +26,8 @@
"fs-extra": "^10.0.0",
"glob": "^7.1.7",
"vuepress": "^1.8.2"
},
"dependencies": {
"@docsearch/js": "^3.0.0-alpha.50"
}
}
......@@ -2,6 +2,129 @@
# 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.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/cache-browser-local-storage/-/cache-browser-local-storage-4.12.1.tgz#23f4f219963b96918d0524acd09d4d646541d888"
integrity sha512-ERFFOnC9740xAkuO0iZTQqm2AzU7Dpz/s+g7o48GlZgx5p9GgNcsuK5eS0GoW/tAK+fnKlizCtlFHNuIWuvfsg==
dependencies:
"@algolia/cache-common" "4.12.1"
"@algolia/cache-common@4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/cache-common/-/cache-common-4.12.1.tgz#d3f1676ca9c404adce0f78d68f6381bedb44cd9c"
integrity sha512-UugTER3V40jT+e19Dmph5PKMeliYKxycNPwrPNADin0RcWNfT2QksK9Ff2N2W7UKraqMOzoeDb4LAJtxcK1a8Q==
"@algolia/cache-in-memory@4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/cache-in-memory/-/cache-in-memory-4.12.1.tgz#0ef6aac2f8feab5b46fc130beb682bbd21b55244"
integrity sha512-U6iaunaxK1lHsAf02UWF58foKFEcrVLsHwN56UkCtwn32nlP9rz52WOcHsgk6TJrL8NDcO5swMjtOQ5XHESFLw==
dependencies:
"@algolia/cache-common" "4.12.1"
"@algolia/client-account@4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/client-account/-/client-account-4.12.1.tgz#e838c9283db2fab32a425dd13c77da321d48fd8b"
integrity sha512-jGo4ConJNoMdTCR2zouO0jO/JcJmzOK6crFxMMLvdnB1JhmMbuIKluOTJVlBWeivnmcsqb7r0v7qTCPW5PAyxQ==
dependencies:
"@algolia/client-common" "4.12.1"
"@algolia/client-search" "4.12.1"
"@algolia/transporter" "4.12.1"
"@algolia/client-analytics@4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/client-analytics/-/client-analytics-4.12.1.tgz#2976d658655a1590cf84cfb596aa75a204f6dec4"
integrity sha512-h1It7KXzIthlhuhfBk7LteYq72tym9maQDUsyRW0Gft8b6ZQahnRak9gcCvKwhcJ1vJoP7T7JrNYGiYSicTD9g==
dependencies:
"@algolia/client-common" "4.12.1"
"@algolia/client-search" "4.12.1"
"@algolia/requester-common" "4.12.1"
"@algolia/transporter" "4.12.1"
"@algolia/client-common@4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/client-common/-/client-common-4.12.1.tgz#104ccefe96bda3ff926bc70c31ff6d17c41b6107"
integrity sha512-obnJ8eSbv+h94Grk83DTGQ3bqhViSWureV6oK1s21/KMGWbb3DkduHm+lcwFrMFkjSUSzosLBHV9EQUIBvueTw==
dependencies:
"@algolia/requester-common" "4.12.1"
"@algolia/transporter" "4.12.1"
"@algolia/client-personalization@4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/client-personalization/-/client-personalization-4.12.1.tgz#f63d1890f95de850e1c8e41c1d57adda521d9e7f"
integrity sha512-sMSnjjPjRgByGHYygV+5L/E8a6RgU7l2GbpJukSzJ9GRY37tHmBHuvahv8JjdCGJ2p7QDYLnQy5bN5Z02qjc7Q==
dependencies:
"@algolia/client-common" "4.12.1"
"@algolia/requester-common" "4.12.1"
"@algolia/transporter" "4.12.1"
"@algolia/client-search@4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/client-search/-/client-search-4.12.1.tgz#fcd7a974be5d39d5c336d7f2e89577ffa66aefdd"
integrity sha512-MwwKKprfY6X2nJ5Ki/ccXM2GDEePvVjZnnoOB2io3dLKW4fTqeSRlC5DRXeFD7UM0vOPPHr4ItV2aj19APKNVQ==
dependencies:
"@algolia/client-common" "4.12.1"
"@algolia/requester-common" "4.12.1"
"@algolia/transporter" "4.12.1"
"@algolia/logger-common@4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/logger-common/-/logger-common-4.12.1.tgz#d6501b4d9d242956257ba8e10f6b4bbf6863baa4"
integrity sha512-fCgrzlXGATNqdFTxwx0GsyPXK+Uqrx1SZ3iuY2VGPPqdt1a20clAG2n2OcLHJpvaa6vMFPlJyWvbqAgzxdxBlQ==
"@algolia/logger-console@4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/logger-console/-/logger-console-4.12.1.tgz#841edd39dd5c5530a69fc66084bfee3254dd0807"
integrity sha512-0owaEnq/davngQMYqxLA4KrhWHiXujQ1CU3FFnyUcMyBR7rGHI48zSOUpqnsAXrMBdSH6rH5BDkSUUFwsh8RkQ==
dependencies:
"@algolia/logger-common" "4.12.1"
"@algolia/requester-browser-xhr@4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/requester-browser-xhr/-/requester-browser-xhr-4.12.1.tgz#2d0c18ee188d7cae0e4a930e5e89989e3c4a816b"
integrity sha512-OaMxDyG0TZG0oqz1lQh9e3woantAG1bLnuwq3fmypsrQxra4IQZiyn1x+kEb69D2TcXApI5gOgrD4oWhtEVMtw==
dependencies:
"@algolia/requester-common" "4.12.1"
"@algolia/requester-common@4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/requester-common/-/requester-common-4.12.1.tgz#95bb6539da7199da3e205341cea8f27267f7af29"
integrity sha512-XWIrWQNJ1vIrSuL/bUk3ZwNMNxl+aWz6dNboRW6+lGTcMIwc3NBFE90ogbZKhNrFRff8zI4qCF15tjW+Fyhpow==
"@algolia/requester-node-http@4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/requester-node-http/-/requester-node-http-4.12.1.tgz#c9df97ff1daa7e58c5c2b1f28cf7163005edccb0"
integrity sha512-awBtwaD+s0hxkA1aehYn8F0t9wqGoBVWgY4JPHBmp1ChO3pK7RKnnvnv7QQa9vTlllX29oPt/BBVgMo1Z3n1Qg==
dependencies:
"@algolia/requester-common" "4.12.1"
"@algolia/transporter@4.12.1":
version "4.12.1"
resolved "https://registry.yarnpkg.com/@algolia/transporter/-/transporter-4.12.1.tgz#61b9829916c474f42e2d4a6eada0d6c138379945"
integrity sha512-BGeNgdEHc6dXIk2g8kdlOoQ6fQ6OIaKQcplEj7HPoi+XZUeAvRi3Pff3QWd7YmybWkjzd9AnTzieTASDWhL+sQ==
dependencies:
"@algolia/cache-common" "4.12.1"
"@algolia/logger-common" "4.12.1"
"@algolia/requester-common" "4.12.1"
"@babel/code-frame@^7.16.7":
version "7.16.7"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.16.7.tgz#44416b6bd7624b998f5b1af5d470856c40138789"
......@@ -923,6 +1046,29 @@
"@babel/helper-validator-identifier" "^7.16.7"
to-fast-properties "^2.0.0"
"@docsearch/css@3.0.0-alpha.50":
version "3.0.0-alpha.50"
resolved "https://registry.yarnpkg.com/@docsearch/css/-/css-3.0.0-alpha.50.tgz#794c6a8d301840a49b55f5b331c7be84b9723643"
integrity sha512-QeWFCQOtS9D+Fi20liKsPXF2j/xWKh52e+P2Z1UATIdPMqmH6zoB2lcUz+cgv6PPVgWUtECeR6VSSUm71LT94w==
"@docsearch/js@^3.0.0-alpha.50":
version "3.0.0-alpha.50"
resolved "https://registry.yarnpkg.com/@docsearch/js/-/js-3.0.0-alpha.50.tgz#8d59834ceb4a27463851e7e7ce9968f3549cc8f2"
integrity sha512-1ap9Wz5oR/Z8yybaCZhsptXU43es3H52eEQUZtmzb8dUWyCW+3iXaKVB/qeMJOQWtggZ/WvZV3YknVIbCMR2dQ==
dependencies:
"@docsearch/react" "3.0.0-alpha.50"
preact "^10.0.0"
"@docsearch/react@3.0.0-alpha.50":
version "3.0.0-alpha.50"
resolved "https://registry.yarnpkg.com/@docsearch/react/-/react-3.0.0-alpha.50.tgz#a7dc547836c2b221fd3aa8eb87bfb47a579ef141"
integrity sha512-oDGV1zZCRYv7MWsh6CyQVthYTRc3b4q+6kKwNYb1/g/Wf/4nJHutpxolFLHdEUDhrJ4Xi8wxwQG+lEwAVBTHPg==
dependencies:
"@algolia/autocomplete-core" "1.5.2"
"@algolia/autocomplete-preset-algolia" "1.5.2"
"@docsearch/css" "3.0.0-alpha.50"
algoliasearch "^4.0.0"
"@mrmlnc/readdir-enhanced@^2.2.1":
version "2.2.1"
resolved "https://registry.yarnpkg.com/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz#524af240d1a360527b730475ecfa1344aa540dde"
......@@ -1635,6 +1781,26 @@ algoliasearch@^3.24.5:
semver "^5.1.0"
tunnel-agent "^0.6.0"
algoliasearch@^4.0.0:
version "4.12.1"
resolved "https://registry.yarnpkg.com/algoliasearch/-/algoliasearch-4.12.1.tgz#574a2c5424c4b6681c026928fb810be2d2ec3924"
integrity sha512-c0dM1g3zZBJrkzE5GA/Nu1y3fFxx3LCzxKzcmp2dgGS8P4CjszB/l3lsSh2MSrrK1Hn/KV4BlbBMXtYgG1Bfrw==
dependencies:
"@algolia/cache-browser-local-storage" "4.12.1"
"@algolia/cache-common" "4.12.1"
"@algolia/cache-in-memory" "4.12.1"
"@algolia/client-account" "4.12.1"
"@algolia/client-analytics" "4.12.1"
"@algolia/client-common" "4.12.1"
"@algolia/client-personalization" "4.12.1"
"@algolia/client-search" "4.12.1"
"@algolia/logger-common" "4.12.1"
"@algolia/logger-console" "4.12.1"
"@algolia/requester-browser-xhr" "4.12.1"
"@algolia/requester-common" "4.12.1"
"@algolia/requester-node-http" "4.12.1"
"@algolia/transporter" "4.12.1"
alphanum-sort@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/alphanum-sort/-/alphanum-sort-1.0.2.tgz#97a1119649b211ad33691d9f9f486a8ec9fbe0a3"
......@@ -6424,6 +6590,11 @@ postcss@^7.0.0, postcss@^7.0.1, postcss@^7.0.14, postcss@^7.0.26, postcss@^7.0.2
picocolors "^0.2.1"
source-map "^0.6.1"
preact@^10.0.0:
version "10.6.6"
resolved "https://registry.yarnpkg.com/preact/-/preact-10.6.6.tgz#f1899bc8dab7c0788b858481532cb3b5d764a520"
integrity sha512-dgxpTFV2vs4vizwKohYKkk7g7rmp1wOOcfd4Tz3IB3Wi+ivZzsn/SpeKJhRENSE+n8sUfsAl4S3HiCVT923ABw==
prepend-http@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册