From fcddcca431ba8d0fed03adff9c1a97226ea8e94c Mon Sep 17 00:00:00 2001 From: jomarmontuya Date: Tue, 23 Jan 2024 09:44:04 +0800 Subject: [PATCH 1/3] feat(algolia): algolia wip --- src/pages/docs/index.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/pages/docs/index.js b/src/pages/docs/index.js index 93a71303b..5a4129f9c 100644 --- a/src/pages/docs/index.js +++ b/src/pages/docs/index.js @@ -207,8 +207,23 @@ export function DocSearchModal() { return ( { - return item.reverse(); + transformItems={(items) => { + const groupBy = items.reduce((acc, item) => { + if (!item.hierarchy) { + return acc; + } + const list = acc[item.hierarchy.lvl1] || []; + + return { + ...acc, + [item.hierarchy.lvl1]: list.concat(item), + }; + }, {}); + + return Object.keys(groupBy).map((level) => ({ + items: groupBy[level], + level, + })); }} placeholder="Search docs..." maxResultsPerGroup={100} From 3baf6f9d3afad5961101a205fcf679e6d5df6eac Mon Sep 17 00:00:00 2001 From: jomarmontuya Date: Wed, 24 Jan 2024 06:57:35 +0800 Subject: [PATCH 2/3] fix(algolia serach): fix algolia search to sort and prioritize pages over contents --- .vscode/settings.json | 2 +- src/pages/docs/index.js | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 7856f76af..5f21e24fb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,6 @@ "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.codeActionsOnSave": { - "source.fixAll.format": false + "source.fixAll.format": "never" } } diff --git a/src/pages/docs/index.js b/src/pages/docs/index.js index 5a4129f9c..d9616082a 100644 --- a/src/pages/docs/index.js +++ b/src/pages/docs/index.js @@ -208,6 +208,9 @@ export function DocSearchModal() { return ( { + /* + * Group items by hierarchy and remove items without hierarchy + */ const groupBy = items.reduce((acc, item) => { if (!item.hierarchy) { return acc; @@ -220,10 +223,36 @@ export function DocSearchModal() { }; }, {}); - return Object.keys(groupBy).map((level) => ({ + /** + * Group based on parent page + */ + const groups = Object.keys(groupBy).map((level) => ({ items: groupBy[level], - level, })); + + const groupItems = groups?.[0]?.items || []; + + /** + * Find the parent page from groupItems + */ + const parent = groupItems?.find((item) => { + if ( + item.hierarchy.lvl1 !== null && + item.hierarchy.lvl2 == null && + item.hierarchy.lvl3 == null && + item.hierarchy.lvl4 == null && + item.hierarchy.lvl5 == null && + item.hierarchy.lvl6 == null + ) { + return item; + } + }); + + /** + * find the index of the parent from groupItems and put it in the first index + */ + const parentIndex = groupItems?.indexOf(parent); + return groupItems.splice(parentIndex, 1).concat(groupItems); }} placeholder="Search docs..." maxResultsPerGroup={100} From 3a7f670cbde6710e662a3107dc43e902dee76314 Mon Sep 17 00:00:00 2001 From: jomarmontuya Date: Wed, 24 Jan 2024 07:00:12 +0800 Subject: [PATCH 3/3] refactor(vscode): revert vscode file changes --- .vscode/settings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 5f21e24fb..7856f76af 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,6 @@ "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.codeActionsOnSave": { - "source.fixAll.format": "never" + "source.fixAll.format": false } }