vuepress-theme-uniapp-official 1.6.16 → 1.6.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -134,6 +134,7 @@
|
|
|
134
134
|
</template>
|
|
135
135
|
|
|
136
136
|
<script>
|
|
137
|
+
import aa from "search-insights";
|
|
137
138
|
import searchPageConfig from '@theme-config/searchPage';
|
|
138
139
|
import NavbarLogo from '../NavbarLogo.vue';
|
|
139
140
|
import Results from './components/Results.vue';
|
|
@@ -163,11 +164,11 @@ const {
|
|
|
163
164
|
} = searchPageConfig;
|
|
164
165
|
const crawlerUrl = 'https://zh.uniapp.dcloud.io/'
|
|
165
166
|
const unidocsUrl = 'https://uniapp.dcloud.io/'
|
|
166
|
-
const docDcloudNetUrl = 'https://doc.dcloud.net.cn
|
|
167
|
+
const docDcloudNetUrl = 'https://doc.dcloud.net.cn'
|
|
167
168
|
|
|
168
169
|
const resolveRoutePathFromUrl = (url, base = '/') => {
|
|
169
170
|
// uni-app-x、uniCloud (doc.dcloud.net.cn 域名下) 等独立站点不需要转换,只需要将爬虫的域名替换为正确域名即可
|
|
170
|
-
if (location.origin
|
|
171
|
+
if (location.origin === docDcloudNetUrl) {
|
|
171
172
|
return url.replace(crawlerUrl, unidocsUrl)
|
|
172
173
|
}
|
|
173
174
|
// unidocs 文档分中英文,因此需要转换回当前站点域名 zh、en
|
|
@@ -384,22 +385,38 @@ export default {
|
|
|
384
385
|
case 'algolia':
|
|
385
386
|
this.showLoading = true;
|
|
386
387
|
this.searchByAlgolia()
|
|
387
|
-
.then(({ hitsPerPage, nbHits, nbPages, page, hits }) => {
|
|
388
|
-
this.
|
|
388
|
+
.then(({ hitsPerPage, nbHits, nbPages, page, hits, queryID, indexName }) => {
|
|
389
|
+
this.noResult = !this.resultList.length;
|
|
390
|
+
this.curHits = nbHits;
|
|
391
|
+
this.pageSize = hitsPerPage;
|
|
392
|
+
this.totalPage = nbPages;
|
|
393
|
+
this.curPage = page + 1;
|
|
394
|
+
|
|
395
|
+
this.resultList = hits.map((item, index) => {
|
|
389
396
|
const items = item.getItems();
|
|
390
397
|
return {
|
|
391
398
|
...item,
|
|
392
399
|
title: removeHighlightTags(items[0]),
|
|
393
400
|
items,
|
|
401
|
+
onSelect: ({ item, event }) => {
|
|
402
|
+
/* aa("convertedObjectIDsAfterSearch", {
|
|
403
|
+
eventName: "Article Read",
|
|
404
|
+
index: "YourIndexName",
|
|
405
|
+
queryID: "query-1",
|
|
406
|
+
objectIDs: ["objectID-1"],
|
|
407
|
+
}); */
|
|
408
|
+
aa("clickedObjectIDsAfterSearch", {
|
|
409
|
+
index: indexName,
|
|
410
|
+
eventName: `[${this.currentCategory.text}] Item Clicked`,
|
|
411
|
+
queryID,
|
|
412
|
+
objectIDs: [item.objectID],
|
|
413
|
+
positions: [(index + 1) + (page * hitsPerPage)],
|
|
414
|
+
});
|
|
415
|
+
item.onSelect()
|
|
416
|
+
}
|
|
394
417
|
};
|
|
395
418
|
});
|
|
396
419
|
|
|
397
|
-
this.noResult = !this.resultList.length;
|
|
398
|
-
this.curHits = nbHits;
|
|
399
|
-
this.pageSize = hitsPerPage;
|
|
400
|
-
this.totalPage = nbPages;
|
|
401
|
-
this.curPage = page + 1;
|
|
402
|
-
|
|
403
420
|
if (this.curPage === 1 && this.showAIMessage) {
|
|
404
421
|
this.resultList.splice(1, 0, this.aiMessage);
|
|
405
422
|
}
|
|
@@ -1,101 +1,119 @@
|
|
|
1
|
-
import algoliasearch from 'algoliasearch
|
|
2
|
-
import
|
|
1
|
+
import algoliasearch from 'algoliasearch';
|
|
2
|
+
import aa from 'search-insights';
|
|
3
|
+
import { removeHighlightTags, groupBy } from './searchUtils';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
searchClient = algoliasearch(appId, apiKey);
|
|
8
|
-
searchClient.addAlgoliaAgent('dcloudsearch', '1.0.0');
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {import('algoliasearch').SearchClient} SearchClient
|
|
7
|
+
*/
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
let searchIndex;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param {string} appId
|
|
14
|
+
* @param {string} apiKey
|
|
15
|
+
* @returns {ReturnType<SearchClient['initIndex']>}
|
|
16
|
+
*/
|
|
17
|
+
function getSearchIndex(appId, apiKey, indexName) {
|
|
18
|
+
if (searchIndex) return searchIndex;
|
|
19
|
+
const searchClient = algoliasearch(appId, apiKey);
|
|
20
|
+
searchIndex = searchClient.initIndex(indexName);
|
|
21
|
+
aa('init', { appId, apiKey });
|
|
22
|
+
searchClient.addAlgoliaAgent('dcloudsearch', '1.0.0');
|
|
23
|
+
|
|
24
|
+
return searchIndex;
|
|
11
25
|
}
|
|
12
26
|
|
|
13
|
-
export function search({
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
27
|
+
export function search({
|
|
28
|
+
query,
|
|
29
|
+
indexName,
|
|
30
|
+
appId,
|
|
31
|
+
apiKey,
|
|
32
|
+
searchParameters = {},
|
|
33
|
+
snippetLength = 0,
|
|
34
|
+
transformItems = () => {},
|
|
35
|
+
onClose = () => {},
|
|
36
|
+
...args
|
|
37
|
+
}) {
|
|
38
|
+
return getSearchIndex(appId, apiKey, indexName)
|
|
39
|
+
.search(query, {
|
|
40
|
+
attributesToRetrieve: [
|
|
41
|
+
'hierarchy.lvl0',
|
|
42
|
+
'hierarchy.lvl1',
|
|
43
|
+
'hierarchy.lvl2',
|
|
44
|
+
'hierarchy.lvl3',
|
|
45
|
+
'hierarchy.lvl4',
|
|
46
|
+
'hierarchy.lvl5',
|
|
47
|
+
'hierarchy.lvl6',
|
|
48
|
+
'content',
|
|
49
|
+
'type',
|
|
50
|
+
'url',
|
|
51
|
+
'url_without_anchor',
|
|
52
|
+
'category',
|
|
53
|
+
'tag',
|
|
54
|
+
],
|
|
55
|
+
attributesToSnippet: [
|
|
56
|
+
`hierarchy.lvl1:${snippetLength}`,
|
|
57
|
+
`hierarchy.lvl2:${snippetLength}`,
|
|
58
|
+
`hierarchy.lvl3:${snippetLength}`,
|
|
59
|
+
`hierarchy.lvl4:${snippetLength}`,
|
|
60
|
+
`hierarchy.lvl5:${snippetLength}`,
|
|
61
|
+
`hierarchy.lvl6:${snippetLength}`,
|
|
62
|
+
`content:${snippetLength}`,
|
|
63
|
+
],
|
|
64
|
+
snippetEllipsisText: '…',
|
|
65
|
+
highlightPreTag: '<mark>',
|
|
66
|
+
highlightPostTag: '</mark>',
|
|
67
|
+
hitsPerPage: 20,
|
|
68
|
+
clickAnalytics: true,
|
|
69
|
+
...searchParameters,
|
|
70
|
+
...args,
|
|
71
|
+
})
|
|
72
|
+
.catch(error => {
|
|
73
|
+
throw error;
|
|
74
|
+
})
|
|
75
|
+
.then(({ hits, hitsPerPage, nbHits, nbPages, page, queryID }) => {
|
|
76
|
+
const sources = groupBy(hits, hit => removeHighlightTags(hit));
|
|
77
|
+
return {
|
|
78
|
+
hitsPerPage,
|
|
79
|
+
nbHits,
|
|
80
|
+
nbPages,
|
|
81
|
+
page,
|
|
82
|
+
hits: Object.values(sources).map((items, index) => {
|
|
83
|
+
return {
|
|
84
|
+
sourceId: `hits${index}`,
|
|
85
|
+
onSelect({ item, event }) {
|
|
86
|
+
// saveRecentSearch(item);
|
|
67
87
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
});
|
|
101
|
-
}
|
|
88
|
+
if (!event.shiftKey && !event.ctrlKey && !event.metaKey) {
|
|
89
|
+
onClose();
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
getItemUrl({ item }) {
|
|
93
|
+
return item.url;
|
|
94
|
+
},
|
|
95
|
+
getItems() {
|
|
96
|
+
return Object.values(groupBy(items, item => item.hierarchy.lvl1))
|
|
97
|
+
.map(transformItems)
|
|
98
|
+
.map(groupedHits =>
|
|
99
|
+
groupedHits.map(item => {
|
|
100
|
+
return {
|
|
101
|
+
...item,
|
|
102
|
+
__docsearch_parent:
|
|
103
|
+
item.type !== 'lvl1' &&
|
|
104
|
+
groupedHits.find(
|
|
105
|
+
siblingItem =>
|
|
106
|
+
siblingItem.type === 'lvl1' && siblingItem.hierarchy.lvl1 === item.hierarchy.lvl1
|
|
107
|
+
),
|
|
108
|
+
};
|
|
109
|
+
})
|
|
110
|
+
)
|
|
111
|
+
.flat();
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
}),
|
|
115
|
+
queryID,
|
|
116
|
+
indexName,
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vuepress-theme-uniapp-official",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.18",
|
|
4
4
|
"description": "uni-app official website theme for vuepress",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -42,13 +42,14 @@
|
|
|
42
42
|
"markdown-it-task-lists": "^2.1.1",
|
|
43
43
|
"marked": "^3.0.8",
|
|
44
44
|
"qr-code-with-logo": "^1.1.0",
|
|
45
|
+
"search-insights": "^2.17.3",
|
|
45
46
|
"vuepress-plugin-juejin-style-copy": "^1.0.4",
|
|
46
47
|
"vuepress-plugin-mermaidjs": "1.9.1",
|
|
47
48
|
"vuepress-plugin-named-chunks": "^1.1.4",
|
|
48
49
|
"vuepress-plugin-zooming": "^1.1.8",
|
|
49
|
-
"vuepress-plugin-
|
|
50
|
+
"vuepress-plugin-check-md2": "^1.0.5",
|
|
50
51
|
"vuepress-plugin-expandable-row": "^1.0.10",
|
|
51
|
-
"vuepress-plugin-
|
|
52
|
+
"vuepress-plugin-noscript-code": "^1.0.2"
|
|
52
53
|
},
|
|
53
54
|
"resolutions": {
|
|
54
55
|
"terser-webpack-plugin": "1.4.6",
|