diff --git a/docs/.vuepress/theme/components/DcloudSearchPage/index.vue b/docs/.vuepress/theme/components/DcloudSearchPage/index.vue new file mode 100644 index 0000000000000000000000000000000000000000..1d778880655700006fc40c1d36ac0af23b6d091a --- /dev/null +++ b/docs/.vuepress/theme/components/DcloudSearchPage/index.vue @@ -0,0 +1,242 @@ + + + + + diff --git a/docs/.vuepress/theme/components/DcloudSearchPage/searchClient.js b/docs/.vuepress/theme/components/DcloudSearchPage/searchClient.js new file mode 100644 index 0000000000000000000000000000000000000000..7c117c8688b0804f6c053c28c228712373fff891 --- /dev/null +++ b/docs/.vuepress/theme/components/DcloudSearchPage/searchClient.js @@ -0,0 +1,96 @@ +import algoliasearch from 'algoliasearch/dist/algoliasearch-lite.esm.browser'; +import { removeHighlightTags, groupBy } from '../../util' + +let searchClient +function createSearchClient(appId, apiKey) { + if (searchClient) return searchClient + searchClient = algoliasearch(appId, apiKey); + searchClient.addAlgoliaAgent('dcloudsearch', '1.0.0'); + + return searchClient +} + +export function search({ query, indexName, appId, apiKey, searchParameters = {}, snippetLength = 0, transformItems = () => { }, ...args }) { + return createSearchClient(appId, apiKey) + .search([ + { + query, + indexName, + params: { + attributesToRetrieve: [ + 'hierarchy.lvl0', + 'hierarchy.lvl1', + 'hierarchy.lvl2', + 'hierarchy.lvl3', + 'hierarchy.lvl4', + 'hierarchy.lvl5', + 'hierarchy.lvl6', + 'content', + 'type', + 'url', + ], + attributesToSnippet: [ + `hierarchy.lvl1:${snippetLength}`, + `hierarchy.lvl2:${snippetLength}`, + `hierarchy.lvl3:${snippetLength}`, + `hierarchy.lvl4:${snippetLength}`, + `hierarchy.lvl5:${snippetLength}`, + `hierarchy.lvl6:${snippetLength}`, + `content:${snippetLength}`, + ], + snippetEllipsisText: '…', + highlightPreTag: '', + highlightPostTag: '', + hitsPerPage: 20, + ...args, + ...searchParameters, + }, + }, + ]) + .catch((error) => { + throw error; + }) + .then(({ results }) => { + const { hits, nbHits } = results[0]; + const sources = groupBy(hits, (hit) => removeHighlightTags(hit)); + + return Object.values(sources).map( + (items, index) => { + return { + sourceId: `hits${index}`, + onSelect({ item, event }) { + // saveRecentSearch(item); + + // if (!event.shiftKey && !event.ctrlKey && !event.metaKey) { + // onClose(); + // } + }, + getItemUrl({ item }) { + return item.url; + }, + getItems() { + return Object.values( + groupBy(items, (item) => item.hierarchy.lvl1) + ) + .map(transformItems) + .map((groupedHits) => + groupedHits.map((item) => { + return { + ...item, + __docsearch_parent: + item.type !== 'lvl1' && + groupedHits.find( + (siblingItem) => + siblingItem.type === 'lvl1' && + siblingItem.hierarchy.lvl1 === + item.hierarchy.lvl1 + ), + }; + }) + ).flat(); + }, + }; + } + ); + }); +} \ No newline at end of file diff --git a/docs/.vuepress/theme/components/Navbar.vue b/docs/.vuepress/theme/components/Navbar.vue index 985bb46f3aefeb2078027acb8931c2401b48cdd8..1d12289924985033ed6010936b00e1e3fe5e3200 100644 --- a/docs/.vuepress/theme/components/Navbar.vue +++ b/docs/.vuepress/theme/components/Navbar.vue @@ -3,29 +3,7 @@