File tree 3 files changed +20
-14
lines changed
src/client/theme-default/components
3 files changed +20
-14
lines changed Original file line number Diff line number Diff line change 1
1
<script setup lang="ts">
2
- import type { DefaultTheme } from ' vitepress/theme'
3
2
import docsearch from ' @docsearch/js'
4
- import { onMounted , watch } from ' vue'
5
- import { useRouter , useRoute } from ' vitepress'
3
+ import { useRoute , useRouter } from ' vitepress'
4
+ import type { DefaultTheme } from ' vitepress/theme'
5
+ import { nextTick , onMounted , watch } from ' vue'
6
6
import { useData } from ' ../composables/data'
7
7
8
8
const props = defineProps <{
@@ -18,7 +18,8 @@ type DocSearchProps = Parameters<typeof docsearch>[0]
18
18
onMounted (update )
19
19
watch (localeIndex , update )
20
20
21
- function update() {
21
+ async function update() {
22
+ await nextTick ()
22
23
const options = {
23
24
... props .algolia ,
24
25
... props .algolia .locales ?.[localeIndex .value ]
@@ -86,12 +87,7 @@ function initialize(userOptions: DefaultTheme.AlgoliaSearchOptions) {
86
87
87
88
function getRelativePath(url : string ) {
88
89
const { pathname, hash } = new URL (url , location .origin )
89
- return (
90
- pathname .replace (
91
- / \. html$ / ,
92
- site .value .cleanUrls ? ' ' : ' .html'
93
- ) + hash
94
- )
90
+ return pathname .replace (/ \. html$ / , site .value .cleanUrls ? ' ' : ' .html' ) + hash
95
91
}
96
92
</script >
97
93
Original file line number Diff line number Diff line change 4
4
computedAsync ,
5
5
debouncedWatch ,
6
6
onKeyStroke ,
7
+ reactify ,
7
8
useEventListener ,
8
9
useLocalStorage ,
9
10
useScrollLock ,
@@ -12,7 +13,7 @@ import {
12
13
import { useFocusTrap } from ' @vueuse/integrations/useFocusTrap'
13
14
import Mark from ' mark.js/src/vanilla.js'
14
15
import MiniSearch , { type SearchResult } from ' minisearch'
15
- import { inBrowser , useRouter , dataSymbol } from ' vitepress'
16
+ import { dataSymbol , inBrowser , useRouter } from ' vitepress'
16
17
import {
17
18
computed ,
18
19
createApp ,
@@ -22,6 +23,7 @@ import {
22
23
onMounted ,
23
24
ref ,
24
25
shallowRef ,
26
+ toRef ,
25
27
watch ,
26
28
watchEffect ,
27
29
type Ref
@@ -352,7 +354,10 @@ const defaultTranslations: { modal: ModalTranslations } = {
352
354
}
353
355
}
354
356
355
- const $t = createTranslate (theme .value .search ?.options , defaultTranslations )
357
+ const $t = reactify (createTranslate )(
358
+ toRef (() => theme .value .search ?.options ),
359
+ defaultTranslations
360
+ )
356
361
357
362
// Back
358
363
Original file line number Diff line number Diff line change 1
1
<script lang="ts" setup>
2
+ import { reactify } from ' @vueuse/core'
3
+ import { toRef } from ' vue'
2
4
import type { ButtonTranslations } from ' ../../../../types/local-search'
3
5
import { useData } from ' ../composables/data'
4
6
import { createTranslate } from ' ../support/translation'
@@ -9,11 +11,14 @@ const { theme } = useData()
9
11
const defaultTranslations: { button: ButtonTranslations } = {
10
12
button: {
11
13
buttonText: ' Search' ,
12
- buttonAriaLabel: ' Search' ,
14
+ buttonAriaLabel: ' Search'
13
15
}
14
16
}
15
17
16
- const $t = createTranslate (theme .value .search ?.options , defaultTranslations )
18
+ const $t = reactify (createTranslate )(
19
+ toRef (() => theme .value .search ?.options ),
20
+ defaultTranslations
21
+ )
17
22
</script >
18
23
19
24
<template >
You can’t perform that action at this time.
0 commit comments