File tree Expand file tree Collapse file tree 3 files changed +41
-10
lines changed Expand file tree Collapse file tree 3 files changed +41
-10
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @opentiny/vue-docs" ,
3
- "version" : " 3.20.3 " ,
3
+ "version" : " 3.20.5 " ,
4
4
"license" : " MIT" ,
5
5
"scripts" : {
6
6
"start" : " vite" ,
49
49
"vue-i18n" : " ^9.1.10" ,
50
50
"vue-router" : " 4.1.5" ,
51
51
"@docsearch/js" : " ^3.8.0" ,
52
- "@docsearch/css" : " ^3.8.0"
52
+ "@docsearch/css" : " ^3.8.0" ,
53
+ "@docsearch/react" : " npm:@docsearch/css"
53
54
},
54
55
"devDependencies" : {
55
56
"@opentiny-internal/unplugin-virtual-template" : " workspace:~" ,
Original file line number Diff line number Diff line change @@ -33,21 +33,25 @@ import css from 'highlight.js/lib/languages/css'
33
33
import html from 'highlight.js/lib/languages/xml'
34
34
import docsearch from '@docsearch/js'
35
35
import '@docsearch/css'
36
+ import { doSearchEverySite } from './tools/docsearch'
36
37
37
38
const envTarget = import . meta. env . VITE_BUILD_TARGET || 'open'
38
39
39
40
hljs . registerLanguage ( 'javascript' , javascript )
40
41
hljs . registerLanguage ( 'css' , css )
41
42
hljs . registerLanguage ( 'html' , html )
42
43
43
- if ( envTarget === 'open' ) {
44
- docsearch ( {
45
- appId : 'AGPA5UXHMH' ,
46
- apiKey : '5fa09fc20270efa61d68e2c2eb0f56df' ,
47
- indexName : 'opentiny' ,
48
- container : '.search-box' ,
49
- debug : false
50
- } )
44
+ docsearch ( {
45
+ appId : 'AGPA5UXHMH' ,
46
+ apiKey : '5fa09fc20270efa61d68e2c2eb0f56df' ,
47
+ indexName : 'opentiny' ,
48
+ container : '.search-box' ,
49
+ debug : false
50
+ } )
51
+
52
+ if ( envTarget !== 'open' ) {
53
+ // 支持本地开发和内网使用全局搜索
54
+ doSearchEverySite ( )
51
55
}
52
56
53
57
// 实验后发现,先调用一次预热一下,后续再调用会有速度的提示,因此在main中预热一下。
Original file line number Diff line number Diff line change
1
+ const HIT_CLASS = 'DocSearch-Hit'
2
+
3
+ const findUrlLink = ( target ) => {
4
+ if ( target ?. nodeName ?. toLocaleLowerCase ?. ( ) === 'a' ) {
5
+ return target . getAttribute ( 'href' )
6
+ } else if ( target ?. parentElement ) {
7
+ return findUrlLink ( target . parentElement )
8
+ }
9
+ }
10
+
11
+ const isAlgoliaHitDom = ( dom ) =>
12
+ dom ?. className ?. includes ?. ( HIT_CLASS ) || dom ?. parentElement ?. className ?. includes ?. ( HIT_CLASS )
13
+
14
+ export const doSearchEverySite = ( ) => {
15
+ window . addEventListener ( 'click' , ( event ) => {
16
+ const target = event . target
17
+ if ( isAlgoliaHitDom ( target ) ) {
18
+ const openUrl = findUrlLink ( target )
19
+ if ( openUrl ) {
20
+ const urlObj = new URL ( openUrl )
21
+ event . preventDefault ( )
22
+ window . location . href = openUrl . replace ( urlObj . origin , window . location . origin )
23
+ }
24
+ }
25
+ } )
26
+ }
You can’t perform that action at this time.
0 commit comments