Skip to content

Commit

Permalink
fix: temporary fix for docsearch navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed Jan 22, 2025
1 parent f93d415 commit e035027
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 59 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@
"*": "prettier --write --ignore-unknown"
},
"dependencies": {
"@docsearch/css": "3.8.2",
"@docsearch/js": "3.8.2",
"@docsearch/css": "^3.8.3",
"@docsearch/js": "^3.8.3",
"@iconify-json/simple-icons": "^1.2.21",
"@shikijs/core": "^2.1.0",
"@shikijs/transformers": "^2.1.0",
Expand Down
66 changes: 33 additions & 33 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 2 additions & 24 deletions src/client/theme-default/components/VPAlgoliaSearchBox.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import docsearch from '@docsearch/js'
import { useRoute, useRouter } from 'vitepress'
import { useRouter } from 'vitepress'
import type { DefaultTheme } from 'vitepress/theme'
import { nextTick, onMounted, watch } from 'vue'
import { useData } from '../composables/data'
Expand All @@ -10,7 +10,6 @@ const props = defineProps<{
}>()
const router = useRouter()
const route = useRoute()
const { site, localeIndex, lang } = useData()
type DocSearchProps = Parameters<typeof docsearch>[0]
Expand Down Expand Up @@ -51,17 +50,7 @@ function initialize(userOptions: DefaultTheme.AlgoliaSearchOptions) {
navigator: {
navigate({ itemUrl }) {
const { pathname: hitPathname } = new URL(
window.location.origin + itemUrl
)
// router doesn't handle same-page navigation so we use the native
// browser location API for anchor navigation
if (route.path === hitPathname) {
window.location.assign(window.location.origin + itemUrl)
} else {
router.go(itemUrl)
}
router.go(itemUrl)
}
},
Expand All @@ -71,17 +60,6 @@ function initialize(userOptions: DefaultTheme.AlgoliaSearchOptions) {
url: getRelativePath(item.url)
})
})
},
hitComponent({ hit, children }) {
return {
__v: null,
type: 'a',
ref: undefined,
constructor: undefined,
key: undefined,
props: { href: hit.url, children }
}
}
}) as DocSearchProps
Expand Down

0 comments on commit e035027

Please sign in to comment.