Skip to content

Commit e9e889f

Browse files
committed
fix: update algolia search component
1 parent 6d5bf2d commit e9e889f

File tree

4 files changed

+2958
-2953
lines changed

4 files changed

+2958
-2953
lines changed

packages/vuepress-common/src/components/molecules/algolia-search-box/AlgoliaSearchBox.vue

+62-86
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
</template>
44

55
<script>
6+
import docsearch from '@docsearch/js'
7+
import '@docsearch/css/dist/style.css'
8+
69
function isSpecialClick (event) {
710
return (
811
event.button === 1 ||
@@ -32,98 +35,71 @@ export default {
3235
3336
methods: {
3437
getRelativePath (absoluteUrl) {
35-
const { pathname, hash } = new URL(absoluteUrl)
38+
const {pathname, hash} = new URL(absoluteUrl)
3639
return pathname.replace(this.$site.base, '/') + hash
3740
},
3841
initialize (userOptions, lang) {
39-
Promise.all([
40-
import(/* webpackChunkName: "docsearch" */ '@docsearch/js'),
41-
import(/* webpackChunkName: "docsearch" */ '@docsearch/css')
42-
]).then(([docsearch]) => {
43-
docsearch = docsearch.default
44-
45-
docsearch(
46-
Object.assign(
47-
{
48-
placeholder: this.$site.themeConfig.searchPlaceholder
42+
const router = this.$router
43+
docsearch(
44+
{
45+
placeholder: this.$site.themeConfig.searchPlaceholder,
46+
...userOptions,
47+
container: '#docsearch',
48+
// #697 Make DocSearch work well in i18n mode.
49+
searchParameters: Object.assign(
50+
{},
51+
lang && {
52+
facetFilters: [`lang:${lang}`].concat(
53+
userOptions.facetFilters || []
54+
)
4955
},
50-
userOptions,
51-
{
52-
container: '#docsearch',
53-
// #697 Make DocSearch work well in i18n mode.
54-
searchParameters: Object.assign(
55-
{},
56-
// lang && {
57-
// facetFilters: [`lang:${lang}`].concat(
58-
// userOptions.facetFilters || []
59-
// )
60-
// },
61-
userOptions.searchParameters
62-
),
63-
navigator: {
64-
navigate: ({ suggestionUrl }) => {
65-
const { pathname: hitPathname } = new URL(
66-
window.location.origin + suggestionUrl
67-
)
56+
userOptions.searchParameters
57+
),
58+
navigator: {
59+
navigate: ({suggestionUrl}) => {
60+
const {pathname: hitPathname} = new URL(
61+
window.location.origin + suggestionUrl
62+
)
6863
69-
// Vue Router doesn't handle same-page navigation so we use
70-
// the native browser location API for anchor navigation.
71-
if (this.$router.history.current.path === hitPathname) {
72-
window.location.assign(
73-
window.location.origin + suggestionUrl
74-
)
75-
} else {
76-
this.$router.push(suggestionUrl)
64+
// Vue Router doesn't handle same-page navigation so we use
65+
// the native browser location API for anchor navigation.
66+
if (router.history.current.path === hitPathname) {
67+
window.location.assign(
68+
window.location.origin + suggestionUrl
69+
)
70+
} else {
71+
router.push(suggestionUrl)
72+
}
73+
}
74+
},
75+
transformItems: items => {
76+
return items.map(item => {
77+
return Object.assign({}, item, {
78+
url: this.getRelativePath(item.url)
79+
})
80+
})
81+
},
82+
hitComponent: ({ hit, children }) =>
83+
({
84+
type: 'a',
85+
ref: undefined,
86+
constructor: undefined,
87+
key: undefined,
88+
props: {
89+
href: hit.url,
90+
// handle `onClick` by `router.push`
91+
onClick: (event) => {
92+
if (isSpecialClick(event)) {
93+
return
7794
}
78-
}
95+
event.preventDefault()
96+
router.push(hit.url)
97+
},
98+
children,
7999
},
80-
transformItems: items => {
81-
return items.map(item => {
82-
return Object.assign({}, item, {
83-
url: this.getRelativePath(item.url)
84-
})
85-
})
86-
},
87-
hitComponent: ({ hit, children }) => {
88-
return {
89-
type: 'a',
90-
ref: undefined,
91-
constructor: undefined,
92-
key: undefined,
93-
props: {
94-
href: hit.url,
95-
onClick: event => {
96-
if (isSpecialClick(event)) {
97-
return
98-
}
99-
100-
// We rely on the native link scrolling when user is
101-
// already on the right anchor because Vue Router doesn't
102-
// support duplicated history entries.
103-
if (this.$router.history.current.fullPath === hit.url) {
104-
return
105-
}
106-
107-
const { pathname: hitPathname } = new URL(
108-
window.location.origin + hit.url
109-
)
110-
111-
// If the hits goes to another page, we prevent the native link behavior
112-
// to leverage the Vue Router loading feature.
113-
if (this.$router.history.current.path !== hitPathname) {
114-
event.preventDefault()
115-
}
116-
117-
this.$router.push(hit.url)
118-
},
119-
children
120-
}
121-
}
122-
}
123-
}
124-
)
125-
)
126-
})
100+
__v: null,
101+
})
102+
})
127103
},
128104
129105
update (options, lang) {
@@ -139,4 +115,4 @@ export default {
139115
--docsearch-highlight-color: var(--docsearch-primary-color);
140116
--docsearch-searchbox-shadow: inset 0 0 0 2px var(--docsearch-primary-color);
141117
}
142-
</style>
118+
</style>

packages/vuepress-theme-tsed/docs/.vuepress/config.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ module.exports = {
5757
apiRedirectUrl: 'https://api-doc.tsed.io',
5858
smoothScroll: true,
5959
lastUpdated: 'Last updated',
60-
// algolia: {
61-
// apiKey: 'f8a038207e461aaac0e2fd16403c2b01',
62-
// indexName: 'ts_ed'
63-
// },
60+
algolia: {
61+
apiKey: "f8a038207e461aaac0e2fd16403c2b01",
62+
indexName: "ts_ed",
63+
appId: 'DH8VVM2E1E'
64+
},
6465
locales: {
6566
'/': {
6667
label: 'English',

packages/vuepress-theme-tsed/package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
"serve:prod": "lite-server --baseDir=\"docs/.vuepress/dist\""
1515
},
1616
"dependencies": {
17-
"@docsearch/css": "3.1.0",
18-
"@docsearch/js": "3.1.0",
17+
"@docsearch/css": "^3.3.0",
18+
"@docsearch/js": "^3.3.0",
19+
"@docsearch/react": "^3.3.0",
1920
"@sass-collective/sass-rem": "^1.7.0",
2021
"@silvanite/vuepress-plugin-tailwind": "^1.3.0",
2122
"@tsed/markdown-it-symbols": "3.20.5",
@@ -63,4 +64,4 @@
6364
"semantic-release": "19.0.2"
6465
},
6566
"peerDependencies": {}
66-
}
67+
}

0 commit comments

Comments
 (0)