Update algolia search

This commit is contained in:
Defectink
2022-04-18 14:56:28 +08:00
parent 0fd635f2b2
commit e0a293ac2e
4 changed files with 61 additions and 53 deletions

View File

@ -20,20 +20,16 @@ export const getHeadings = (source: string) => {
const regex = /<h2 id="(.*?)">(.*?)<\/h2>/g;
const linkRegx = /id="(.*?)"/;
if (source.match(regex)) {
return source.match(regex)?.map((heading) => {
const headingText = heading
.replace(/<h2 id="(.*?)">/, '')
.replace(/<\/h2>/, '');
return source.match(regex)?.map((heading) => {
const headingText = heading
.replace(/<h2 id="(.*?)">/, '')
.replace(/<\/h2>/, '');
const link = '#' + heading.match(linkRegx)?.[1];
const link = '#' + heading.match(linkRegx)?.[1];
return {
text: headingText,
link,
};
});
}
return [];
return {
text: headingText,
link,
};
});
};