Skip to content

Commit 5c520eb

Browse files
committed
improve search
1 parent 1989aaf commit 5c520eb

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

vuepress/docs/.vuepress/theme/helpers/generateSidebar.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,18 @@ export const generateSidebar = (): SidebarConfig => {
1818
cwd: docsDirectory,
1919
mark: true,
2020
})
21-
.filter((d: string) => statSync(path.join(docsDirectory, d)).isDirectory());
21+
.filter((d: string) => statSync(path.join(docsDirectory, d)).isDirectory())
22+
.sort((a, b) => {
23+
const aStartsWithB = a.toLowerCase().startsWith("b");
24+
const bStartsWithB = b.toLowerCase().startsWith("b");
25+
26+
// If only one starts with 'b', put it last
27+
if (aStartsWithB && !bStartsWithB) return 1;
28+
if (!aStartsWithB && bStartsWithB) return -1;
29+
30+
// If both start with 'b' or neither starts with 'b', sort alphabetically
31+
return a.localeCompare(b);
32+
});
2233

2334
// get all md files in the root of docs
2435
const rootMdFiles = glob
@@ -80,7 +91,6 @@ export const generateSidebar = (): SidebarConfig => {
8091
collapsible: true,
8192
link: indexFile ? `/${repoPath}/${indexFile}` : undefined,
8293
children: sortByOrderProperty(children),
83-
order: sectionFrontmatter["sectionOrder"] ?? 1,
8494
};
8595
});
8696

vuepress/docs/.vuepress/theme/theme.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,27 @@ export default hopeTheme({
166166
},
167167
},
168168

169+
maxSuggestions: 10,
170+
171+
isSearchable: (page) => page.path !== "/",
172+
169173
getExtraFields: (page) => {
170174
const extraFields = [];
171175

172176
if (page.content) {
173-
extraFields.push(page.content);
177+
const cleanContent = page.content
178+
.replace(/#{1,6}\s+/g, "") // Remove headers
179+
.replace(/\*\*([^*]+)\*\*/g, "$1") // Remove bold
180+
.replace(/\*([^*]+)\*/g, "$1") // Remove italic
181+
.replace(/`([^`]+)`/g, "$1") // Remove inline code
182+
.replace(/```[\s\S]*?```/g, "") // Remove code blocks
183+
.replace(/\[([^\]]+)\]\([^)]+\)/g, "$1") // Remove links, keep text
184+
.split("\n")
185+
.filter((line) => line.trim().length > 10) // Only meaningful lines
186+
.slice(0, 10) // Limit to first 10 paragraphs
187+
.join(" ");
188+
189+
extraFields.push(cleanContent);
174190
}
175191

176192
return extraFields;

0 commit comments

Comments
 (0)