Files
medusa-store/www/apps/resources/app/references/[...slug]/page.tsx
Shahed Nasser b23f0f8188 docs: change notes across docs based on redesign (#8662)
Change the prerequisites / soon / other notes based on latest redesign

Depends on #8661
2024-08-23 07:59:48 +00:00

81 lines
2.1 KiB
TypeScript

import { MDXRemote } from "next-mdx-remote/rsc"
import path from "path"
import { promises as fs } from "fs"
import { notFound } from "next/navigation"
import {
typeListLinkFixerPlugin,
localLinksRehypePlugin,
workflowDiagramLinkFixerPlugin,
prerequisitesLinkFixerPlugin,
} from "remark-rehype-plugins"
import MDXComponents from "@/components/MDXComponents"
import mdxOptions from "../../../mdx-options.mjs"
import { slugChanges } from "../../../generated/slug-changes.mjs"
import { filesMap } from "../../../generated/files-map.mjs"
type PageProps = {
params: {
slug: string[]
}
}
export default async function ReferencesPage({ params }: PageProps) {
const { slug } = params
// ensure that Vercel loads references files
path.join(process.cwd(), "references")
const monoRepoPath = path.resolve("..", "..", "..")
const pathname = `/references/${slug.join("/")}`
const fileDetails =
slugChanges.find((f) => f.newSlug === pathname) ||
filesMap.find((f) => f.pathname === pathname)
if (!fileDetails) {
return notFound()
}
const fullPath = path.join(monoRepoPath, fileDetails.filePath)
const fileContent = await fs.readFile(fullPath, "utf-8")
const pluginOptions = {
filePath: fullPath,
basePath: process.cwd(),
}
return (
<MDXRemote
source={fileContent}
components={MDXComponents}
options={{
mdxOptions: {
rehypePlugins: [
...mdxOptions.options.rehypePlugins,
[
typeListLinkFixerPlugin,
{
...pluginOptions,
checkLinksType: "md",
},
],
[
workflowDiagramLinkFixerPlugin,
{
...pluginOptions,
checkLinksType: "value",
},
],
[
prerequisitesLinkFixerPlugin,
{
...pluginOptions,
checkLinksType: "value",
},
],
[localLinksRehypePlugin, pluginOptions],
],
remarkPlugins: mdxOptions.options.remarkPlugins,
},
}}
/>
)
}