forked from medusajs/medusa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add clean markdown version of all documentation pages (medusajs…
…#11308) * added route to book * added to resources * added route to ui * added to user guide
- Loading branch information
1 parent
87db3f0
commit 98236c8
Showing
30 changed files
with
1,085 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { getCleanMd } from "docs-utils" | ||
import { existsSync } from "fs" | ||
import { unstable_cache } from "next/cache" | ||
import { notFound } from "next/navigation" | ||
import { NextRequest, NextResponse } from "next/server" | ||
import path from "path" | ||
import { | ||
addUrlToRelativeLink, | ||
crossProjectLinksPlugin, | ||
localLinksRehypePlugin, | ||
} from "remark-rehype-plugins" | ||
import type { Plugin } from "unified" | ||
|
||
type Params = { | ||
params: Promise<{ slug: string[] }> | ||
} | ||
|
||
export async function GET(req: NextRequest, { params }: Params) { | ||
const { slug } = await params | ||
|
||
// keep this so that Vercel keeps the files in deployment | ||
const basePath = path.join(process.cwd(), "app") | ||
const filePath = path.join(basePath, ...slug, "page.mdx") | ||
|
||
if (!existsSync(filePath)) { | ||
return notFound() | ||
} | ||
|
||
const cleanMdContent = await getCleanMd_(filePath, { | ||
before: [ | ||
[ | ||
crossProjectLinksPlugin, | ||
{ | ||
baseUrl: process.env.NEXT_PUBLIC_BASE_URL, | ||
projectUrls: { | ||
resources: { | ||
url: process.env.NEXT_PUBLIC_RESOURCES_URL, | ||
}, | ||
"user-guide": { | ||
url: process.env.NEXT_PUBLIC_RESOURCES_URL, | ||
}, | ||
ui: { | ||
url: process.env.NEXT_PUBLIC_RESOURCES_URL, | ||
}, | ||
api: { | ||
url: process.env.NEXT_PUBLIC_RESOURCES_URL, | ||
}, | ||
}, | ||
useBaseUrl: | ||
process.env.NODE_ENV === "production" || | ||
process.env.VERCEL_ENV === "production", | ||
}, | ||
], | ||
[localLinksRehypePlugin], | ||
] as unknown as Plugin[], | ||
after: [ | ||
[addUrlToRelativeLink, { url: process.env.NEXT_PUBLIC_BASE_URL }], | ||
] as unknown as Plugin[], | ||
}) | ||
|
||
return new NextResponse(cleanMdContent, { | ||
headers: { | ||
"Content-Type": "text/markdown", | ||
}, | ||
}) | ||
} | ||
|
||
const getCleanMd_ = unstable_cache( | ||
async (filePath: string, plugins?: { before?: Plugin[]; after?: Plugin[] }) => | ||
getCleanMd({ filePath, plugins }), | ||
["clean-md"], | ||
{ | ||
revalidate: 3600, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { NextResponse } from "next/server" | ||
import type { NextRequest } from "next/server" | ||
|
||
export function middleware(request: NextRequest) { | ||
return NextResponse.rewrite( | ||
new URL( | ||
`/md-content${request.nextUrl.pathname.replace("/index.html.md", "")}`, | ||
request.url | ||
) | ||
) | ||
} | ||
|
||
export const config = { | ||
matcher: "/:path*/index.html.md", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { getCleanMd } from "docs-utils" | ||
import { existsSync } from "fs" | ||
import { unstable_cache } from "next/cache" | ||
import { notFound } from "next/navigation" | ||
import { NextRequest, NextResponse } from "next/server" | ||
import path from "path" | ||
import { | ||
addUrlToRelativeLink, | ||
crossProjectLinksPlugin, | ||
localLinksRehypePlugin, | ||
} from "remark-rehype-plugins" | ||
import type { Plugin } from "unified" | ||
import { filesMap } from "../../../generated/files-map.mjs" | ||
import { slugChanges } from "../../../generated/slug-changes.mjs" | ||
|
||
type Params = { | ||
params: Promise<{ slug: string[] }> | ||
} | ||
|
||
export async function GET(req: NextRequest, { params }: Params) { | ||
const { slug = ["/"] } = await params | ||
|
||
// keep this so that Vercel keeps the files in deployment | ||
path.join(process.cwd(), "app") | ||
path.join(process.cwd(), "references") | ||
|
||
const filePathFromMap = await getFileFromMaps(`/${slug.join("/")}`) | ||
if (!filePathFromMap) { | ||
return notFound() | ||
} | ||
|
||
const filePath = path.join(path.resolve("..", "..", ".."), filePathFromMap) | ||
|
||
if (!existsSync(filePath)) { | ||
return notFound() | ||
} | ||
|
||
const cleanMdContent = await getCleanMd_(filePath, { | ||
before: [ | ||
[ | ||
crossProjectLinksPlugin, | ||
{ | ||
baseUrl: process.env.NEXT_PUBLIC_BASE_URL, | ||
projectUrls: { | ||
docs: { | ||
url: process.env.NEXT_PUBLIC_DOCS_URL, | ||
path: "", | ||
}, | ||
"user-guide": { | ||
url: process.env.NEXT_PUBLIC_USER_GUIDE_URL, | ||
}, | ||
ui: { | ||
url: process.env.NEXT_PUBLIC_UI_URL, | ||
}, | ||
api: { | ||
url: process.env.NEXT_PUBLIC_API_URL, | ||
}, | ||
}, | ||
useBaseUrl: | ||
process.env.NODE_ENV === "production" || | ||
process.env.VERCEL_ENV === "production", | ||
}, | ||
], | ||
[localLinksRehypePlugin], | ||
] as unknown as Plugin[], | ||
after: [ | ||
[addUrlToRelativeLink, { url: process.env.NEXT_PUBLIC_BASE_URL }], | ||
] as unknown as Plugin[], | ||
}) | ||
|
||
return new NextResponse(cleanMdContent, { | ||
headers: { | ||
"Content-Type": "text/markdown", | ||
}, | ||
}) | ||
} | ||
|
||
const getCleanMd_ = unstable_cache( | ||
async (filePath: string, plugins?: { before?: Plugin[]; after?: Plugin[] }) => | ||
getCleanMd({ filePath, plugins }), | ||
["clean-md"], | ||
{ | ||
revalidate: 3600, | ||
} | ||
) | ||
|
||
const getFileFromMaps = unstable_cache( | ||
async (path: string) => { | ||
return ( | ||
slugChanges.find((slugChange) => slugChange.newSlug === path)?.filePath || | ||
filesMap.find((file) => file.pathname === path)?.filePath | ||
) | ||
}, | ||
["file-map"], | ||
{ | ||
revalidate: 3600, | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { NextResponse } from "next/server" | ||
import type { NextRequest } from "next/server" | ||
|
||
export function middleware(request: NextRequest) { | ||
return NextResponse.rewrite( | ||
new URL( | ||
`${request.nextUrl.basePath}/md-content${request.nextUrl.pathname.replace("/index.html.md", "")}`, | ||
request.url | ||
) | ||
) | ||
} | ||
|
||
export const config = { | ||
matcher: "/:path*/index.html.md", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.