vuepress-theme-uniapp-official 1.6.17 → 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,12 @@
1
1
  # vuepress-theme-uniapp-official
2
2
 
3
+ ## 1.6.18
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: 优化搜索体验
8
+ - fix: 修复点击事件 positions 不正确
9
+
3
10
  ## 1.6.17
4
11
 
5
12
  ### 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>
@@ -386,30 +386,37 @@ export default {
386
386
  this.showLoading = true;
387
387
  this.searchByAlgolia()
388
388
  .then(({ hitsPerPage, nbHits, nbPages, page, hits, queryID, indexName }) => {
389
- this.resultList = hits.map(item => {
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) => {
390
396
  const items = item.getItems();
391
397
  return {
392
398
  ...item,
393
399
  title: removeHighlightTags(items[0]),
394
400
  items,
395
401
  onSelect: ({ item, event }) => {
402
+ /* aa("convertedObjectIDsAfterSearch", {
403
+ eventName: "Article Read",
404
+ index: "YourIndexName",
405
+ queryID: "query-1",
406
+ objectIDs: ["objectID-1"],
407
+ }); */
396
408
  aa("clickedObjectIDsAfterSearch", {
397
409
  index: indexName,
398
410
  eventName: `[${this.currentCategory.text}] Item Clicked`,
399
411
  queryID,
400
412
  objectIDs: [item.objectID],
401
- positions: [1],
413
+ positions: [(index + 1) + (page * hitsPerPage)],
402
414
  });
415
+ item.onSelect()
403
416
  }
404
417
  };
405
418
  });
406
419
 
407
- this.noResult = !this.resultList.length;
408
- this.curHits = nbHits;
409
- this.pageSize = hitsPerPage;
410
- this.totalPage = nbPages;
411
- this.curPage = page + 1;
412
-
413
420
  if (this.curPage === 1 && this.showAIMessage) {
414
421
  this.resultList.splice(1, 0, this.aiMessage);
415
422
  }
@@ -1,106 +1,119 @@
1
- import algoliasearch from 'algoliasearch/dist/algoliasearch-lite.esm.browser';
2
- import aa from "search-insights";
3
- import { removeHighlightTags, groupBy } from './searchUtils'
1
+ import algoliasearch from 'algoliasearch';
2
+ import aa from 'search-insights';
3
+ import { removeHighlightTags, groupBy } from './searchUtils';
4
4
 
5
- let searchClient
6
- function createSearchClient(appId, apiKey) {
7
- if (searchClient) return searchClient
8
- searchClient = algoliasearch(appId, apiKey);
9
- aa("init", { appId, apiKey });
10
- searchClient.addAlgoliaAgent('dcloudsearch', '1.0.0');
5
+ /**
6
+ * @typedef {import('algoliasearch').SearchClient} SearchClient
7
+ */
11
8
 
12
- 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;
13
25
  }
14
26
 
15
- export function search({ query, indexName, appId, apiKey, searchParameters = {}, snippetLength = 0, transformItems = () => { }, onClose = () => { }, ...args }) {
16
- return createSearchClient(appId, apiKey)
17
- .search([
18
- {
19
- query,
20
- indexName,
21
- params: {
22
- attributesToRetrieve: [
23
- 'hierarchy.lvl0',
24
- 'hierarchy.lvl1',
25
- 'hierarchy.lvl2',
26
- 'hierarchy.lvl3',
27
- 'hierarchy.lvl4',
28
- 'hierarchy.lvl5',
29
- 'hierarchy.lvl6',
30
- 'content',
31
- 'type',
32
- 'url',
33
- 'url_without_anchor',
34
- 'category',
35
- 'tag'
36
- ],
37
- attributesToSnippet: [
38
- `hierarchy.lvl1:${snippetLength}`,
39
- `hierarchy.lvl2:${snippetLength}`,
40
- `hierarchy.lvl3:${snippetLength}`,
41
- `hierarchy.lvl4:${snippetLength}`,
42
- `hierarchy.lvl5:${snippetLength}`,
43
- `hierarchy.lvl6:${snippetLength}`,
44
- `content:${snippetLength}`,
45
- ],
46
- snippetEllipsisText: '…',
47
- highlightPreTag: '<mark>',
48
- highlightPostTag: '</mark>',
49
- hitsPerPage: 20,
50
- clickAnalytics: true,
51
- ...searchParameters,
52
- ...args,
53
- },
54
- },
55
- ])
56
- .catch((error) => {
57
- throw error;
58
- })
59
- .then(({ results }) => {
60
- const { hits, hitsPerPage, nbHits, nbPages, page, queryID } = results[0];
61
- const sources = groupBy(hits, (hit) => removeHighlightTags(hit));
62
- return {
63
- hitsPerPage, nbHits, nbPages, page,
64
- hits: Object.values(sources).map(
65
- (items, index) => {
66
- return {
67
- sourceId: `hits${index}`,
68
- onSelect({ item, event }) {
69
- // 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);
70
87
 
71
- if (!event.shiftKey && !event.ctrlKey && !event.metaKey) {
72
- onClose()
73
- }
74
- },
75
- getItemUrl({ item }) {
76
- return item.url;
77
- },
78
- getItems() {
79
- return Object.values(
80
- groupBy(items, (item) => item.hierarchy.lvl1)
81
- )
82
- .map(transformItems)
83
- .map((groupedHits) =>
84
- groupedHits.map((item) => {
85
- return {
86
- ...item,
87
- __docsearch_parent:
88
- item.type !== 'lvl1' &&
89
- groupedHits.find(
90
- (siblingItem) =>
91
- siblingItem.type === 'lvl1' &&
92
- siblingItem.hierarchy.lvl1 ===
93
- item.hierarchy.lvl1
94
- ),
95
- };
96
- })
97
- ).flat();
98
- },
99
- };
100
- }
101
- ),
102
- queryID,
103
- indexName
104
- }
105
- });
106
- }
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.17",
3
+ "version": "1.6.18",
4
4
  "description": "uni-app official website theme for vuepress",
5
5
  "main": "index.js",
6
6
  "repository": {