Files
medusa-store/www/apps/resources/app/references/[...slug]/page.tsx
Shahed Nasser 938f3bd934 docs: update to next 15 + eslint 9 (#9839)
* update next

* updated react

* update eslint

* finish updating eslint

* fix content lint errors

* fix docs test

* fix vale action

* fix installation errors
2024-11-13 17:03:17 +02:00

82 lines
2.2 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: Promise<{
slug: string[]
}>
}
export default async function ReferencesPage(props: PageProps) {
const params = await props.params
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,
},
}}
/>
)
}