From a3becb730fe7dd17a1505703a8e4496ffc849e87 Mon Sep 17 00:00:00 2001 From: zhengqi zhang <770166635@qq.com> Date: Wed, 9 Aug 2023 13:04:16 +0800 Subject: [PATCH] fix search index issue --- src/components/Header/Search/SearchModal.tsx | 11 +---------- src/pages/en/search-index.astro | 15 ++++++++++++--- src/pages/es/search-index.astro | 15 ++++++++++++--- src/pages/search-index.astro | 16 ++++++++++++---- src/pages/zh/search-index.astro | 15 ++++++++++++--- 5 files changed, 49 insertions(+), 23 deletions(-) diff --git a/src/components/Header/Search/SearchModal.tsx b/src/components/Header/Search/SearchModal.tsx index f09a689c2..335e32fc6 100644 --- a/src/components/Header/Search/SearchModal.tsx +++ b/src/components/Header/Search/SearchModal.tsx @@ -84,15 +84,6 @@ function EmptyQueryBoundary({ children, fallback }) { return children } -function transformPath(path) { - path = path.replace('src/content/docs', ''); - - path = path.substring(0, path.lastIndexOf('.')) || path; - - return path; -} - - function NoResultsBoundary({ children }) { const { results } = useInstantSearch() @@ -127,7 +118,7 @@ function CustomHits({ title, hitClassName, ...props }: UseHitsProps & { title: s
  • !post.frontmatter.draft)] -const postsMdx = [...(await Astro.glob("../../content/**/*.mdx")).filter((post) => !post.frontmatter.draft)] +const posts = [...(await Astro.glob("../../content/docs/en/**/*.md")).filter((post) => !post.frontmatter.draft)] +const postsMdx = [...(await Astro.glob("../../content/docs/en/**/*.mdx")).filter((post) => !post.frontmatter.draft)] const postsMdxWithContent = postsMdx.map((post) => { const url = new URL(post.file, import.meta.url) const content = fs.readFileSync(url, "utf-8") @@ -17,6 +17,15 @@ const postsMdxWithContent = postsMdx.map((post) => { }) const markDownFiles = [...posts, ...postsMdxWithContent] const allContent = [...pages, ...posts, ...postsMdx] + +function transformPath(path) { + path = path.split("src/content/docs")[1] + + path = path.substring(0, path.lastIndexOf(".")) || path + + return path +} + const transformMarkdownInstancesToIndexes = async (instances: MarkdownInstance>[]) => { return Promise.all( instances.map(async (instance) => { @@ -26,7 +35,7 @@ const transformMarkdownInstancesToIndexes = async (instances: MarkdownInstance !post.frontmatter.draft)] -const postsMdx = [...(await Astro.glob("../../content/**/*.mdx")).filter((post) => !post.frontmatter.draft)] +const posts = [...(await Astro.glob("../../content/docs/en/**/*.md")).filter((post) => !post.frontmatter.draft)] +const postsMdx = [...(await Astro.glob("../../content/docs/en/**/*.mdx")).filter((post) => !post.frontmatter.draft)] const postsMdxWithContent = postsMdx.map((post) => { const url = new URL(post.file, import.meta.url) const content = fs.readFileSync(url, "utf-8") @@ -17,6 +17,15 @@ const postsMdxWithContent = postsMdx.map((post) => { }) const markDownFiles = [...posts, ...postsMdxWithContent] const allContent = [...pages, ...posts, ...postsMdx] + +function transformPath(path) { + path = path.split("src/content/docs")[1] + + path = path.substring(0, path.lastIndexOf(".")) || path + + return path +} + const transformMarkdownInstancesToIndexes = async (instances: MarkdownInstance>[]) => { return Promise.all( instances.map(async (instance) => { @@ -26,7 +35,7 @@ const transformMarkdownInstancesToIndexes = async (instances: MarkdownInstance !post.frontmatter.draft)] -const postsMdx = [...(await Astro.glob("../content/**/*.mdx")).filter((post) => !post.frontmatter.draft)] +const posts = [...(await Astro.glob("../content/docs/en/**/*.md")).filter((post) => !post.frontmatter.draft)] +const postsMdx = [...(await Astro.glob("../content/docs/en/**/*.mdx")).filter((post) => !post.frontmatter.draft)] const postsMdxWithContent = postsMdx.map((post) => { const url = new URL(post.file, import.meta.url) const content = fs.readFileSync(url, "utf-8") @@ -18,6 +17,15 @@ const postsMdxWithContent = postsMdx.map((post) => { }) const markDownFiles = [...posts, ...postsMdxWithContent] const allContent = [...pages, ...posts, ...postsMdx] + +function transformPath(path) { + path = path.split("src/content/docs")[1] + + path = path.substring(0, path.lastIndexOf(".")) || path + + return path +} + const transformMarkdownInstancesToIndexes = async (instances: MarkdownInstance>[]) => { return Promise.all( instances.map(async (instance) => { @@ -27,7 +35,7 @@ const transformMarkdownInstancesToIndexes = async (instances: MarkdownInstance !post.frontmatter.draft)] -const postsMdx = [...(await Astro.glob("../../content/**/*.mdx")).filter((post) => !post.frontmatter.draft)] +const posts = [...(await Astro.glob("../../content/docs/en/**/*.md")).filter((post) => !post.frontmatter.draft)] +const postsMdx = [...(await Astro.glob("../../content/docs/en/**/*.mdx")).filter((post) => !post.frontmatter.draft)] const postsMdxWithContent = postsMdx.map((post) => { const url = new URL(post.file, import.meta.url) const content = fs.readFileSync(url, "utf-8") @@ -17,6 +17,15 @@ const postsMdxWithContent = postsMdx.map((post) => { }) const markDownFiles = [...posts, ...postsMdxWithContent] const allContent = [...pages, ...posts, ...postsMdx] + +function transformPath(path) { + path = path.split("src/content/docs")[1] + + path = path.substring(0, path.lastIndexOf(".")) || path + + return path +} + const transformMarkdownInstancesToIndexes = async (instances: MarkdownInstance>[]) => { return Promise.all( instances.map(async (instance) => { @@ -26,7 +35,7 @@ const transformMarkdownInstancesToIndexes = async (instances: MarkdownInstance