Skip to content

Commit

Permalink
docs: migrated to algolia service
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed Nov 24, 2021
1 parent 7a0660e commit 599db50
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 91 deletions.
123 changes: 61 additions & 62 deletions docs/components/AlgoliaSearchBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
</template>

<script>
import docsearch from '@docsearch/js';
function isSpecialClick(event) {
return event.button === 1 || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
}
Expand All @@ -26,71 +28,66 @@ export default {
return this.stripTrailingSlash(url);
},
initialize(userOptions, lang) {
Promise.all([
import(/* webpackChunkName: "docsearch" */ '@docsearch/js'),
import(/* webpackChunkName: "docsearch" */ '@docsearch/css'),
]).then(([docsearch]) => {
docsearch = docsearch.default;
const { algoliaOptions = {} } = userOptions;
docsearch(
Object.assign({}, userOptions, {
container: '#docsearch',
debug: process.env.NODE_ENV !== 'production',
navigator: {
navigate: ({ suggestionUrl }) => {
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 (this.$router.history.current.path === hitPathname) {
window.location.assign(window.location.origin + suggestionUrl);
} else {
this.$router.push(suggestionUrl);
initialize(userOptions) {
docsearch({
...userOptions,
container: '#docsearch',
debug: process.env.NODE_ENV !== 'production',
navigator: {
navigate: ({ suggestionUrl }) => {
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 (this.$router.history.current.path === hitPathname) {
window.location.assign(window.location.origin + suggestionUrl);
return;
}
this.$router.push(suggestionUrl);
},
},
transformItems: items => {
return items.map(item => {
return {
...item,
url: this.getRelativePath(item.url),
};
});
},
hitComponent: ({ hit, children }) => {
return {
type: 'a',
ref: undefined,
constructor: undefined,
key: undefined,
props: {
href: hit.url,
onClick: event => {
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 (this.$router.history.current.fullPath === hit.url) {
return;
}
},
},
transformItems: items => {
return items.map(item => {
return Object.assign({}, item, {
url: this.getRelativePath(item.url),
});
});
},
hitComponent: ({ hit, children }) => {
return {
type: 'a',
ref: undefined,
constructor: undefined,
key: undefined,
props: {
href: hit.url,
onClick: event => {
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 (this.$router.history.current.fullPath === hit.url) {
return;
}
const { pathname, hash } = new URL(window.location.origin + hit.url);
// If the hits goes to another page, we prevent the native link behavior
// to leverage the Vue Router loading feature.
if (this.$router.history.current.path !== pathname) {
event.preventDefault();
}
// makes sure to remove base path to prevent duplicate base paths
const url = pathname.replace('/v4/', '/') + hash;
this.$router.push(url);
},
children,
},
};
const { pathname, hash } = new URL(window.location.origin + hit.url);
// If the hits goes to another page, we prevent the native link behavior
// to leverage the Vue Router loading feature.
if (this.$router.history.current.path !== pathname) {
event.preventDefault();
}
// makes sure to remove base path to prevent duplicate base paths
const url = pathname.replace('/v4/', '/') + hash;
this.$router.push(url);
},
children,
},
})
);
__v: null,
};
},
});
},
update(options, lang) {
Expand All @@ -110,6 +107,8 @@ export default {
</script>

<style lang="postcss">
@import '@docsearch/css';
.DocSearch {
font-family: Arial, Helvetica, sans-serif;
--docsearch-primary-color: var(--accent);
Expand Down
3 changes: 2 additions & 1 deletion docs/nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export default {
publicRuntimeConfig: {
appURL: process.env.NODE_ENV === 'production' ? 'https://vee-validate.logaretm.com/v4' : 'http://localhost:3000',
algolia: {
apiKey: '36539f933d7a7cd4801b6f07dea75ed8',
apiKey: '63f5a0934f840b36e5d33af009ddff15',
appId: 'F6BYW6NAIH',
indexName: 'vee-validate-v4',
},
},
Expand Down
4 changes: 2 additions & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"export": "nuxt export"
},
"dependencies": {
"@docsearch/css": "^1.0.0-alpha.28",
"@docsearch/js": "^1.0.0-alpha.28",
"@docsearch/css": "^3.0.0-alpha.41",
"@docsearch/js": "^3.0.0-alpha.41",
"@nuxt/content": "^1.13.1",
"@nuxtjs/pwa": "^3.3.5",
"@nuxtjs/tailwindcss": "^4.2.1",
Expand Down
61 changes: 35 additions & 26 deletions docs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@
# yarn lockfile v1


"@algolia/autocomplete-core@1.2.2":
version "1.2.2"
resolved "https://registry.yarnpkg.com/@algolia/autocomplete-core/-/autocomplete-core-1.2.2.tgz#c121e70c78fd0175c989a219918124ad7758e48b"
integrity sha512-JOQaURze45qVa8OOFDh+ozj2a/ObSRsVyz6Zd0aiBeej+RSTqrr1hDVpGNbbXYLW26G5ujuc9QIdH+rBHn95nw==
dependencies:
"@algolia/autocomplete-shared" "1.2.2"

"@algolia/autocomplete-preset-algolia@1.2.2":
version "1.2.2"
resolved "https://registry.yarnpkg.com/@algolia/autocomplete-preset-algolia/-/autocomplete-preset-algolia-1.2.2.tgz#da734ef9e42a5f64cdad2dfc81c4e9fbf805d976"
integrity sha512-AZkh+bAMaJDzMZTelFOXJTJqkp5VPGH8W3n0B+Ggce7DdozlMRsDLguKTCQAkZ0dJ1EbBPyFL5ztL/JImB137Q==
dependencies:
"@algolia/autocomplete-shared" "1.2.2"

"@algolia/autocomplete-shared@1.2.2":
version "1.2.2"
resolved "https://registry.yarnpkg.com/@algolia/autocomplete-shared/-/autocomplete-shared-1.2.2.tgz#ff25dc308f2a296b2b9b325f1e3b57498eea3e0c"
integrity sha512-mLTl7d2C1xVVazHt/bqh9EE/u2lbp5YOxLDdcjILXmUqOs5HH1D4SuySblXaQG1uf28FhTqMGp35qE5wJQnqAw==

"@algolia/cache-browser-local-storage@4.10.5":
version "4.10.5"
resolved "https://registry.yarnpkg.com/@algolia/cache-browser-local-storage/-/cache-browser-local-storage-4.10.5.tgz#961cf07cf59955de17af13bd74f7806bd2119553"
Expand Down Expand Up @@ -1012,39 +1031,29 @@
resolved "https://registry.yarnpkg.com/@csstools/convert-colors/-/convert-colors-1.4.0.tgz#ad495dc41b12e75d588c6db8b9834f08fa131eb7"
integrity sha512-5a6wqoJV/xEdbRNKVo6I4hO3VjyDq//8q2f9I6PBAvMesJHFauXDorcNCsr9RzvsZnaWi5NYCcfyqP1QeFHFbw==

"@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/css@3.0.0-alpha.41", "@docsearch/css@^3.0.0-alpha.41":
version "3.0.0-alpha.41"
resolved "https://registry.yarnpkg.com/@docsearch/css/-/css-3.0.0-alpha.41.tgz#c5c8e803541bd157ad86e764c2c1e9f1b5a68592"
integrity sha512-AP1jqcF/9jCrm4s0lcES3QAtHueyipKjd14L/pguk0CZYK7uI7hC0FWodmRmrgK3/HST9jiHa1waUMR6ZYedlQ==

"@docsearch/js@^1.0.0-alpha.28":
version "1.0.0-alpha.28"
resolved "https://registry.yarnpkg.com/@docsearch/js/-/js-1.0.0-alpha.28.tgz#f0fde7b8a6b1e1d8a7ae1e7655c43d959b457b2b"
integrity sha512-2g7aPhBy7FoEyeZW2G3LYHWVa8CFvqyozEz8PXt3hyywdFcmEIqmoCRwn8kboVftrOKCjtPcuLCewsaBoB3uiw==
"@docsearch/js@^3.0.0-alpha.41":
version "3.0.0-alpha.41"
resolved "https://registry.yarnpkg.com/@docsearch/js/-/js-3.0.0-alpha.41.tgz#f669e50fb93037f28dfc7d2407da043c4299ef97"
integrity sha512-dD9r+ygmzJEE50wtnRUs6I7TMD4ui7igEQlt74jZsn0SUPk6AlIP2ldII8brJHr0I4qs4OzlyrvV6ikAqjR6sw==
dependencies:
"@docsearch/react" "^1.0.0-alpha.28"
"@docsearch/react" "3.0.0-alpha.41"
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==
"@docsearch/react@3.0.0-alpha.41":
version "3.0.0-alpha.41"
resolved "https://registry.yarnpkg.com/@docsearch/react/-/react-3.0.0-alpha.41.tgz#07e85a664e85f251ce3d13153abce65a4d5997ab"
integrity sha512-UL0Gdter/NUea04lGuBGH0GzQ2/2q/hBfn7Rjo71rRKbjtfkQCM92leJ9tZ+9j9sFLoyuHb9XMm/B8vCjWwTEg==
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"
"@algolia/autocomplete-core" "1.2.2"
"@algolia/autocomplete-preset-algolia" "1.2.2"
"@docsearch/css" "3.0.0-alpha.41"
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==

"@gar/promisify@^1.0.1":
version "1.1.2"
resolved "https://registry.yarnpkg.com/@gar/promisify/-/promisify-1.1.2.tgz#30aa825f11d438671d585bd44e7fd564535fc210"
Expand Down

0 comments on commit 599db50

Please sign in to comment.