From e2bceab5fd26a1b0992cc2bb477f77ae5d8b331d Mon Sep 17 00:00:00 2001 From: Defectink Date: Mon, 18 Apr 2022 15:39:36 +0800 Subject: [PATCH] Updatee search --- scripts/build-search.mjs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/scripts/build-search.mjs b/scripts/build-search.mjs index a55041c..c9f2390 100644 --- a/scripts/build-search.mjs +++ b/scripts/build-search.mjs @@ -20,17 +20,21 @@ const postLists = () => { const slug = f.replace(/\.mdx$/, ''); const regex = /^#{2}(?!#)(.*)/gm; - content.match(regex)?.map((heading) => { + content.match(regex)?.map((h) => { + const heading = h.substring(3); + myPosts.push({ content: null, hierarchy: { lvl0: 'Post', lvl1: slug, - lvl2: heading.substring(3), + lvl2: heading, }, type: 'lvl2', objectID: `${nanoid()}-https://rua.plus/p/${slug}`, - url: 'https://rua.plus/p/' + slug, + url: `https://rua.plus/p/${slug}#${heading + .toLocaleLowerCase() + .replace(/ /g, '-')}`, }); }); @@ -42,7 +46,7 @@ const postLists = () => { }, type: 'lvl1', objectID: `${nanoid()}-https://rua.plus/p/${slug}`, - url: 'https://rua.plus/p/' + slug, + url: `https://rua.plus/p/${slug}`, }); }); return myPosts; @@ -92,5 +96,4 @@ function test() { posts.map((p) => console.log(p)); } // test(); - main();