Skip to content

Commit 74635b9

Browse files
committed
docs: migrated to algolia service
1 parent 18b762a commit 74635b9

File tree

4 files changed

+100
-89
lines changed

4 files changed

+100
-89
lines changed

docs/components/AlgoliaSearchBox.vue

Lines changed: 61 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
</template>
44

55
<script>
6+
import docsearch from '@docsearch/js';
7+
68
function isSpecialClick(event) {
79
return event.button === 1 || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
810
}
@@ -22,71 +24,68 @@ export default {
2224
},
2325
getRelativePath(absoluteUrl) {
2426
const { pathname, hash } = new URL(absoluteUrl);
25-
const url = pathname.replace('/v4/', '/') + hash;
27+
const url = pathname + hash;
28+
2629
return this.stripTrailingSlash(url);
2730
},
28-
initialize(userOptions, lang) {
29-
Promise.all([
30-
import(/* webpackChunkName: "docsearch" */ '@docsearch/js'),
31-
import(/* webpackChunkName: "docsearch" */ '@docsearch/css'),
32-
]).then(([docsearch]) => {
33-
docsearch = docsearch.default;
34-
const { algoliaOptions = {} } = userOptions;
35-
docsearch(
36-
Object.assign({}, userOptions, {
37-
container: '#docsearch',
38-
debug: process.env.NODE_ENV !== 'production',
39-
navigator: {
40-
navigate: ({ suggestionUrl }) => {
41-
const { pathname: hitPathname } = new URL(window.location.origin + suggestionUrl);
42-
// Vue Router doesn't handle same-page navigation so we use
43-
// the native browser location API for anchor navigation.
44-
if (this.$router.history.current.path === hitPathname) {
45-
window.location.assign(window.location.origin + suggestionUrl);
46-
} else {
47-
this.$router.push(suggestionUrl);
31+
initialize(userOptions) {
32+
docsearch({
33+
...userOptions,
34+
container: '#docsearch',
35+
debug: process.env.NODE_ENV !== 'production',
36+
navigator: {
37+
navigate: ({ suggestionUrl }) => {
38+
const { pathname: hitPathname } = new URL(window.location.origin + suggestionUrl);
39+
// Vue Router doesn't handle same-page navigation so we use
40+
// the native browser location API for anchor navigation.
41+
if (this.$router.history.current.path === hitPathname) {
42+
window.location.assign(window.location.origin + suggestionUrl);
43+
return;
44+
}
45+
46+
this.$router.push(suggestionUrl);
47+
},
48+
},
49+
transformItems: items => {
50+
return items.map(item => {
51+
return {
52+
...item,
53+
url: this.getRelativePath(item.url),
54+
};
55+
});
56+
},
57+
hitComponent: ({ hit, children }) => {
58+
return {
59+
type: 'a',
60+
ref: undefined,
61+
constructor: undefined,
62+
key: undefined,
63+
props: {
64+
href: hit.url,
65+
onClick: event => {
66+
if (isSpecialClick(event)) {
67+
return;
4868
}
69+
// We rely on the native link scrolling when user is
70+
// already on the right anchor because Vue Router doesn't
71+
// support duplicated history entries.
72+
if (this.$router.history.current.fullPath === hit.url) {
73+
return;
74+
}
75+
76+
const { pathname: hitPathname } = new URL(window.location.origin + hit.url);
77+
// If the hits goes to another page, we prevent the native link behavior
78+
// to leverage the Vue Router loading feature.
79+
if (this.$router.history.current.path !== hitPathname) {
80+
event.preventDefault();
81+
}
82+
this.$router.push(hit.url);
4983
},
84+
children,
5085
},
51-
transformItems: items => {
52-
return items.map(item => {
53-
return Object.assign({}, item, {
54-
url: this.getRelativePath(item.url),
55-
});
56-
});
57-
},
58-
hitComponent: ({ hit, children }) => {
59-
return {
60-
type: 'a',
61-
ref: undefined,
62-
constructor: undefined,
63-
key: undefined,
64-
props: {
65-
href: hit.url,
66-
onClick: event => {
67-
if (isSpecialClick(event)) {
68-
return;
69-
}
70-
// We rely on the native link scrolling when user is
71-
// already on the right anchor because Vue Router doesn't
72-
// support duplicated history entries.
73-
if (this.$router.history.current.fullPath === hit.url) {
74-
return;
75-
}
76-
const { pathname: hitPathname } = new URL(window.location.origin + hit.url);
77-
// If the hits goes to another page, we prevent the native link behavior
78-
// to leverage the Vue Router loading feature.
79-
if (this.$router.history.current.path !== hitPathname) {
80-
event.preventDefault();
81-
}
82-
this.$router.push(hit.url);
83-
},
84-
children,
85-
},
86-
};
87-
},
88-
})
89-
);
86+
__v: null,
87+
};
88+
},
9089
});
9190
},
9291
update(options, lang) {
@@ -106,6 +105,8 @@ export default {
106105
</script>
107106

108107
<style lang="postcss">
108+
@import '@docsearch/css';
109+
109110
.DocSearch {
110111
font-family: Arial, Helvetica, sans-serif;
111112
--accent: #9580ff;

docs/nuxt.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export default {
2121
appURL: 'https://villus.logaretm.com',
2222

2323
algolia: {
24-
apiKey: 'e41cc2209bb0e139d471edd1c86b8bdd',
24+
apiKey: '434db5d5d2794ec2818d4665d631a15b',
25+
appId: '1SMG3JU76L',
2526
indexName: 'villus',
2627
},
2728
},

docs/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
}
2121
},
2222
"dependencies": {
23-
"@docsearch/css": "^1.0.0-alpha.28",
24-
"@docsearch/js": "^1.0.0-alpha.28",
23+
"@docsearch/css": "^3.0.0-alpha.41",
24+
"@docsearch/js": "^3.0.0-alpha.41",
2525
"@nuxt/content": "^1.13.1",
2626
"@nuxtjs/pwa": "^3.3.5",
2727
"lodash.groupby": "^4.6.0",

docs/yarn.lock

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22
# yarn lockfile v1
33

44

5+
"@algolia/autocomplete-core@1.2.2":
6+
version "1.2.2"
7+
resolved "https://registry.yarnpkg.com/@algolia/autocomplete-core/-/autocomplete-core-1.2.2.tgz#c121e70c78fd0175c989a219918124ad7758e48b"
8+
integrity sha512-JOQaURze45qVa8OOFDh+ozj2a/ObSRsVyz6Zd0aiBeej+RSTqrr1hDVpGNbbXYLW26G5ujuc9QIdH+rBHn95nw==
9+
dependencies:
10+
"@algolia/autocomplete-shared" "1.2.2"
11+
12+
"@algolia/autocomplete-preset-algolia@1.2.2":
13+
version "1.2.2"
14+
resolved "https://registry.yarnpkg.com/@algolia/autocomplete-preset-algolia/-/autocomplete-preset-algolia-1.2.2.tgz#da734ef9e42a5f64cdad2dfc81c4e9fbf805d976"
15+
integrity sha512-AZkh+bAMaJDzMZTelFOXJTJqkp5VPGH8W3n0B+Ggce7DdozlMRsDLguKTCQAkZ0dJ1EbBPyFL5ztL/JImB137Q==
16+
dependencies:
17+
"@algolia/autocomplete-shared" "1.2.2"
18+
19+
"@algolia/autocomplete-shared@1.2.2":
20+
version "1.2.2"
21+
resolved "https://registry.yarnpkg.com/@algolia/autocomplete-shared/-/autocomplete-shared-1.2.2.tgz#ff25dc308f2a296b2b9b325f1e3b57498eea3e0c"
22+
integrity sha512-mLTl7d2C1xVVazHt/bqh9EE/u2lbp5YOxLDdcjILXmUqOs5HH1D4SuySblXaQG1uf28FhTqMGp35qE5wJQnqAw==
23+
524
"@algolia/cache-browser-local-storage@4.5.1":
625
version "4.5.1"
726
resolved "https://registry.yarnpkg.com/@algolia/cache-browser-local-storage/-/cache-browser-local-storage-4.5.1.tgz#bdf58c30795683fd48310c552c3a10f10fb26e2b"
@@ -1114,39 +1133,29 @@
11141133
resolved "https://registry.yarnpkg.com/@csstools/convert-colors/-/convert-colors-1.4.0.tgz#ad495dc41b12e75d588c6db8b9834f08fa131eb7"
11151134
integrity sha512-5a6wqoJV/xEdbRNKVo6I4hO3VjyDq//8q2f9I6PBAvMesJHFauXDorcNCsr9RzvsZnaWi5NYCcfyqP1QeFHFbw==
11161135

1117-
"@docsearch/css@^1.0.0-alpha.28":
1118-
version "1.0.0-alpha.28"
1119-
resolved "https://registry.yarnpkg.com/@docsearch/css/-/css-1.0.0-alpha.28.tgz#c8a2cd8c1bb3a6855c51892e9dbdab5d42fe6e23"
1120-
integrity sha512-1AhRzVdAkrWwhaxTX6/R7SnFHz8yLz1W8I/AldlTrfbNvZs9INk1FZiEFTJdgHaP68nhgQNWSGlQiDiI3y2RYg==
1136+
"@docsearch/css@3.0.0-alpha.41", "@docsearch/css@^3.0.0-alpha.41":
1137+
version "3.0.0-alpha.41"
1138+
resolved "https://registry.yarnpkg.com/@docsearch/css/-/css-3.0.0-alpha.41.tgz#c5c8e803541bd157ad86e764c2c1e9f1b5a68592"
1139+
integrity sha512-AP1jqcF/9jCrm4s0lcES3QAtHueyipKjd14L/pguk0CZYK7uI7hC0FWodmRmrgK3/HST9jiHa1waUMR6ZYedlQ==
11211140

1122-
"@docsearch/js@^1.0.0-alpha.28":
1123-
version "1.0.0-alpha.28"
1124-
resolved "https://registry.yarnpkg.com/@docsearch/js/-/js-1.0.0-alpha.28.tgz#f0fde7b8a6b1e1d8a7ae1e7655c43d959b457b2b"
1125-
integrity sha512-2g7aPhBy7FoEyeZW2G3LYHWVa8CFvqyozEz8PXt3hyywdFcmEIqmoCRwn8kboVftrOKCjtPcuLCewsaBoB3uiw==
1141+
"@docsearch/js@^3.0.0-alpha.41":
1142+
version "3.0.0-alpha.41"
1143+
resolved "https://registry.yarnpkg.com/@docsearch/js/-/js-3.0.0-alpha.41.tgz#f669e50fb93037f28dfc7d2407da043c4299ef97"
1144+
integrity sha512-dD9r+ygmzJEE50wtnRUs6I7TMD4ui7igEQlt74jZsn0SUPk6AlIP2ldII8brJHr0I4qs4OzlyrvV6ikAqjR6sw==
11261145
dependencies:
1127-
"@docsearch/react" "^1.0.0-alpha.28"
1146+
"@docsearch/react" "3.0.0-alpha.41"
11281147
preact "^10.0.0"
11291148

1130-
"@docsearch/react@^1.0.0-alpha.28":
1131-
version "1.0.0-alpha.28"
1132-
resolved "https://registry.yarnpkg.com/@docsearch/react/-/react-1.0.0-alpha.28.tgz#4f039ed79f8b3332b19a57677b219aebc5010e9d"
1133-
integrity sha512-XjJOnCBXn+UZmtuDmgzlVIHnnvh6yHVwG4aFq8AXN6xJEIX3f180FvGaowFWAxgdtHplJxFGux0Xx4piHqBzIw==
1149+
"@docsearch/react@3.0.0-alpha.41":
1150+
version "3.0.0-alpha.41"
1151+
resolved "https://registry.yarnpkg.com/@docsearch/react/-/react-3.0.0-alpha.41.tgz#07e85a664e85f251ce3d13153abce65a4d5997ab"
1152+
integrity sha512-UL0Gdter/NUea04lGuBGH0GzQ2/2q/hBfn7Rjo71rRKbjtfkQCM92leJ9tZ+9j9sFLoyuHb9XMm/B8vCjWwTEg==
11341153
dependencies:
1135-
"@docsearch/css" "^1.0.0-alpha.28"
1136-
"@francoischalifour/autocomplete-core" "^1.0.0-alpha.28"
1137-
"@francoischalifour/autocomplete-preset-algolia" "^1.0.0-alpha.28"
1154+
"@algolia/autocomplete-core" "1.2.2"
1155+
"@algolia/autocomplete-preset-algolia" "1.2.2"
1156+
"@docsearch/css" "3.0.0-alpha.41"
11381157
algoliasearch "^4.0.0"
11391158

1140-
"@francoischalifour/autocomplete-core@^1.0.0-alpha.28":
1141-
version "1.0.0-alpha.28"
1142-
resolved "https://registry.yarnpkg.com/@francoischalifour/autocomplete-core/-/autocomplete-core-1.0.0-alpha.28.tgz#6b9d8491288e77f831e9b345d461623b0d3f5005"
1143-
integrity sha512-rL9x+72btViw+9icfBKUJjZj87FgjFrD2esuTUqtj4RAX3s4AuVZiN8XEsfjQBSc6qJk31cxlvqZHC/BIyYXgg==
1144-
1145-
"@francoischalifour/autocomplete-preset-algolia@^1.0.0-alpha.28":
1146-
version "1.0.0-alpha.28"
1147-
resolved "https://registry.yarnpkg.com/@francoischalifour/autocomplete-preset-algolia/-/autocomplete-preset-algolia-1.0.0-alpha.28.tgz#a5ad7996f42e43e4acbb4e0010d663746d0e9997"
1148-
integrity sha512-bprfNmYt1opFUFEtD2XfY/kEsm13bzHQgU80uMjhuK0DJ914IjolT1GytpkdM6tJ4MBvyiJPP+bTtWO+BZ7c7w==
1149-
11501159
"@fullhuman/postcss-purgecss@^2.1.2":
11511160
version "2.3.0"
11521161
resolved "https://registry.yarnpkg.com/@fullhuman/postcss-purgecss/-/postcss-purgecss-2.3.0.tgz#50a954757ec78696615d3e118e3fee2d9291882e"

0 commit comments

Comments
 (0)