Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit39a8980

Browse files
authored
Merge pull requestwilfredinni#133 from wilfredinni:next
Fix algolia weird behavior when clicking on a result
2 parentsa138dbf +f6e9570 commit39a8980

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

‎src/components/AlgoliaDocSearch.vue‎

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
a
12
<script setup lang="ts">
23
importdocsearchfrom'@docsearch/js'
34
@@ -15,7 +16,17 @@ function initialize() {
1516
const options=Object.assign({},userOptions, {
1617
navigator: {
1718
navigate({itemUrl }: { itemUrl:string }) {
18-
router.push(itemUrl)
19+
const {pathname: hitPathname }=newURL(
20+
window.location.origin+itemUrl
21+
)
22+
23+
// router doesn't handle same-page navigation so we use the native
24+
// browser location API for anchor navigation
25+
if (route.path===hitPathname) {
26+
window.location.assign(window.location.origin+itemUrl)
27+
}else {
28+
router.push(itemUrl)
29+
}
1930
},
2031
},
2132
@@ -35,6 +46,7 @@ function initialize() {
3546
3647
props: {
3748
href:hit.url,
49+
children,
3850
3951
onClick(event:MouseEvent) {
4052
if (isSpecialClick(event))return
@@ -51,29 +63,41 @@ function initialize() {
5163
// behavior to leverage the Router loading feature.
5264
if (route.path!==hitPathname)event.preventDefault()
5365
54-
router.push(hit.url)
66+
// router doesn't handle same-page navigation so we use the native
67+
// browser location API for anchor navigation
68+
if (route.path===hitPathname) {
69+
window.location.assign(window.location.origin+hit.url)
70+
}else {
71+
router.push(hit.url)
72+
}
5573
},
56-
57-
children,
5874
},
5975
}
6076
},
6177
})
6278
79+
// @ts-ignore: Unreachable code error
6380
docsearch(options)
6481
}
6582
83+
/**
84+
* Check if event is special click to avoid closing the DocSearch too soon.
85+
*/
6686
const isSpecialClick= (event:MouseEvent)=>
6787
event.button===1||
6888
event.altKey||
6989
event.ctrlKey||
7090
event.metaKey||
7191
event.shiftKey
7292
93+
/**
94+
* Gets the relative path from an absolute URL provided by the DocSearch instance.
95+
*/
7396
const getRelativePath= (absoluteUrl:string)=> {
7497
const { pathname, hash }=newURL(absoluteUrl)
75-
76-
returnpathname+hash
98+
const url=window.location.origin
99+
const relativeUrl=pathname.replace(url,'/')+hash
100+
returnrelativeUrl.replace(/\/+$/,'')
77101
}
78102
79103
onMounted(()=> {

‎src/pages/changelog.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ updated: July 19, 2022
77

88
#Changelog
99

10-
<!-- ## [Unreleased](https://github.com/wilfredinni/python-cheatsheet/tree/next)-->
10+
##[Unreleased](https://github.com/wilfredinni/python-cheatsheet/tree/next)
11+
12+
- Fixed_Algolia docsearch_ weir behavior when clicking on a result.
1113

1214
##2022-10-02
1315

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp