Skip to content

Commit

Permalink
Merge pull request #27 from scroll-tech/fix-search-index-issue
Browse files Browse the repository at this point in the history
Fix search index issue
  • Loading branch information
dghelm authored Aug 9, 2023
2 parents f286a0f + a3becb7 commit 63066bf
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 23 deletions.
11 changes: 1 addition & 10 deletions src/components/Header/Search/SearchModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -127,7 +118,7 @@ function CustomHits({ title, hitClassName, ...props }: UseHitsProps & { title: s
<li style={{ borderRadius: "var(--border-radius-primary)" }}>
<a
// style={{ padding: "var(--space-1x) var(--space-2x)" }}
href={hit.url && transformPath(hit.url)}
href={hit.url}
className={clsx(styles.hit, hitClassName, "paragraph-200")}
dangerouslySetInnerHTML={{
__html: hit._highlightResult.title.value,
Expand Down
15 changes: 12 additions & 3 deletions src/pages/en/search-index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,24 @@ changeLanguage("en")
// import .astro files
const pages = await Astro.glob("../**/*.astro")
// import .md files
const posts = [...(await Astro.glob("../../content/**/*.md")).filter((post) => !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")
return { ...post, rawContent: () => content }
})
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<Record<string, any>>[]) => {
return Promise.all(
instances.map(async (instance) => {
Expand All @@ -26,7 +35,7 @@ const transformMarkdownInstancesToIndexes = async (instances: MarkdownInstance<R
return {
title,
headings,
url: instance.url,
url: transformPath(instance.file),
section,
description: metadata?.description ?? undefined,
content,
Expand Down
15 changes: 12 additions & 3 deletions src/pages/es/search-index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,24 @@ changeLanguage("es")
// import .astro files
const pages = await Astro.glob("../**/*.astro")
// import .md files
const posts = [...(await Astro.glob("../../content/**/*.md")).filter((post) => !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")
return { ...post, rawContent: () => content }
})
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<Record<string, any>>[]) => {
return Promise.all(
instances.map(async (instance) => {
Expand All @@ -26,7 +35,7 @@ const transformMarkdownInstancesToIndexes = async (instances: MarkdownInstance<R
return {
title,
headings,
url: instance.url,
url: transformPath(instance.file),
section,
description: metadata?.description ?? undefined,
content,
Expand Down
16 changes: 12 additions & 4 deletions src/pages/search-index.astro
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
---
import { changeLanguage } from "i18next"
import { MarkdownInstance } from "astro"
import { getCollection } from "astro:content"
import fs from "node:fs"
changeLanguage("en")
// import .astro files
const pages = await Astro.glob("./**/*.astro")
// import .md files
const posts = [...(await Astro.glob("../content/**/*.md")).filter((post) => !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")
return { ...post, rawContent: () => content }
})
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<Record<string, any>>[]) => {
return Promise.all(
instances.map(async (instance) => {
Expand All @@ -27,7 +35,7 @@ const transformMarkdownInstancesToIndexes = async (instances: MarkdownInstance<R
return {
title,
headings,
url: instance.url,
url: transformPath(instance.file),
section,
description: metadata?.description ?? undefined,
content,
Expand Down
15 changes: 12 additions & 3 deletions src/pages/zh/search-index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,24 @@ changeLanguage("zh")
// import .astro files
const pages = await Astro.glob("../**/*.astro")
// import .md files
const posts = [...(await Astro.glob("../../content/**/*.md")).filter((post) => !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")
return { ...post, rawContent: () => content }
})
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<Record<string, any>>[]) => {
return Promise.all(
instances.map(async (instance) => {
Expand All @@ -26,7 +35,7 @@ const transformMarkdownInstancesToIndexes = async (instances: MarkdownInstance<R
return {
title,
headings,
url: instance.url,
url: transformPath(instance.file),
section,
description: metadata?.description ?? undefined,
content,
Expand Down

0 comments on commit 63066bf

Please sign in to comment.