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
@@ -1,5 +1,18 @@
1
1
  # vuepress-theme-uniapp-official
2
2
 
3
+ ## 1.6.18
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: 优化搜索体验
8
+ - fix: 修复点击事件 positions 不正确
9
+
10
+ ## 1.6.17
11
+
12
+ ### Patch Changes
13
+
14
+ - feat: Algolia 搜索结果点击事件分析
15
+
3
16
  ## 1.6.16
4
17
 
5
18
  ### Patch Changes
@@ -10,7 +10,7 @@
10
10
  :key="[title, item.objectID].join(':')"
11
11
  :item="item"
12
12
  :index="index"
13
- @click.native="event => onSelect({ item, event })"
13
+ @click.native.stop="event => onSelect({ item, event, index })"
14
14
  />
15
15
  </template>
16
16
  </ul>
@@ -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.includes(docDcloudNetUrl)) {
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.resultList = hits.map(item => {
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/dist/algoliasearch-lite.esm.browser';
2
- import { removeHighlightTags, groupBy } from './searchUtils'
1
+ import algoliasearch from 'algoliasearch';
2
+ import aa from 'search-insights';
3
+ import { removeHighlightTags, groupBy } from './searchUtils';
3
4
 
4
- let searchClient
5
- function createSearchClient(appId, apiKey) {
6
- if (searchClient) return searchClient
7
- searchClient = algoliasearch(appId, apiKey);
8
- searchClient.addAlgoliaAgent('dcloudsearch', '1.0.0');
5
+ /**
6
+ * @typedef {import('algoliasearch').SearchClient} SearchClient
7
+ */
9
8
 
10
- return searchClient
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({ query, indexName, appId, apiKey, searchParameters = {}, snippetLength = 0, transformItems = () => { }, onClose = () => { }, ...args }) {
14
- return createSearchClient(appId, apiKey)
15
- .search([
16
- {
17
- query,
18
- indexName,
19
- params: {
20
- attributesToRetrieve: [
21
- 'hierarchy.lvl0',
22
- 'hierarchy.lvl1',
23
- 'hierarchy.lvl2',
24
- 'hierarchy.lvl3',
25
- 'hierarchy.lvl4',
26
- 'hierarchy.lvl5',
27
- 'hierarchy.lvl6',
28
- 'content',
29
- 'type',
30
- 'url',
31
- 'url_without_anchor',
32
- 'category',
33
- 'tag'
34
- ],
35
- attributesToSnippet: [
36
- `hierarchy.lvl1:${snippetLength}`,
37
- `hierarchy.lvl2:${snippetLength}`,
38
- `hierarchy.lvl3:${snippetLength}`,
39
- `hierarchy.lvl4:${snippetLength}`,
40
- `hierarchy.lvl5:${snippetLength}`,
41
- `hierarchy.lvl6:${snippetLength}`,
42
- `content:${snippetLength}`,
43
- ],
44
- snippetEllipsisText: '…',
45
- highlightPreTag: '<mark>',
46
- highlightPostTag: '</mark>',
47
- hitsPerPage: 20,
48
- ...searchParameters,
49
- ...args,
50
- },
51
- },
52
- ])
53
- .catch((error) => {
54
- throw error;
55
- })
56
- .then(({ results }) => {
57
- const { hits, hitsPerPage, nbHits, nbPages, page } = results[0];
58
- const sources = groupBy(hits, (hit) => removeHighlightTags(hit));
59
- return {
60
- hitsPerPage, nbHits, nbPages, page,
61
- hits: Object.values(sources).map(
62
- (items, index) => {
63
- return {
64
- sourceId: `hits${index}`,
65
- onSelect({ item, event }) {
66
- // saveRecentSearch(item);
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
- if (!event.shiftKey && !event.ctrlKey && !event.metaKey) {
69
- onClose()
70
- }
71
- },
72
- getItemUrl({ item }) {
73
- return item.url;
74
- },
75
- getItems() {
76
- return Object.values(
77
- groupBy(items, (item) => item.hierarchy.lvl1)
78
- )
79
- .map(transformItems)
80
- .map((groupedHits) =>
81
- groupedHits.map((item) => {
82
- return {
83
- ...item,
84
- __docsearch_parent:
85
- item.type !== 'lvl1' &&
86
- groupedHits.find(
87
- (siblingItem) =>
88
- siblingItem.type === 'lvl1' &&
89
- siblingItem.hierarchy.lvl1 ===
90
- item.hierarchy.lvl1
91
- ),
92
- };
93
- })
94
- ).flat();
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.16",
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-noscript-code": "^1.0.2",
50
+ "vuepress-plugin-check-md2": "^1.0.5",
50
51
  "vuepress-plugin-expandable-row": "^1.0.10",
51
- "vuepress-plugin-check-md2": "^1.0.5"
52
+ "vuepress-plugin-noscript-code": "^1.0.2"
52
53
  },
53
54
  "resolutions": {
54
55
  "terser-webpack-plugin": "1.4.6",