Skip to content

Commit 98236c8

Browse files
authored
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
1 parent 87db3f0 commit 98236c8

File tree

30 files changed

+1085
-191
lines changed

30 files changed

+1085
-191
lines changed

www/apps/book/app/learn/fundamentals/plugins/create/page.mdx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -205,40 +205,40 @@ You can now build your plugin's customizations. The following guide explains how
205205
<CardList
206206
items={[
207207
{
208-
text: "Create a module",
209-
link: "/learn/fundamentals/modules",
208+
title: "Create a module",
209+
href: "/learn/fundamentals/modules",
210210
},
211211
{
212-
text: "Create a module link",
213-
link: "/learn/fundamentals/module-links",
212+
title: "Create a module link",
213+
href: "/learn/fundamentals/module-links",
214214
},
215215
{
216-
text: "Create a workflow",
217-
link: "/learn/fundamentals/workflows",
216+
title: "Create a workflow",
217+
href: "/learn/fundamentals/workflows",
218218
},
219219
{
220-
text: "Add a workflow hook",
221-
link: "/learn/fundamentals/workflows/add-workflow-hook",
220+
title: "Add a workflow hook",
221+
href: "/learn/fundamentals/workflows/add-workflow-hook",
222222
},
223223
{
224-
text: "Create an API route",
225-
link: "/learn/fundamentals/api-routes",
224+
title: "Create an API route",
225+
href: "/learn/fundamentals/api-routes",
226226
},
227227
{
228-
text: "Add a subscriber",
229-
link: "/learn/fundamentals/events-and-subscribers",
228+
title: "Add a subscriber",
229+
href: "/learn/fundamentals/events-and-subscribers",
230230
},
231231
{
232-
text: "Add a scheduled job",
233-
link: "/learn/fundamentals/scheduled-jobs",
232+
title: "Add a scheduled job",
233+
href: "/learn/fundamentals/scheduled-jobs",
234234
},
235235
{
236-
text: "Add an admin widget",
237-
link: "/learn/fundamentals/admin/widgets",
236+
title: "Add an admin widget",
237+
href: "/learn/fundamentals/admin/widgets",
238238
},
239239
{
240-
text: "Add an admin UI route",
241-
link: "/learn/fundamentals/admin/ui-routes",
240+
title: "Add an admin UI route",
241+
href: "/learn/fundamentals/admin/ui-routes",
242242
}
243243
]}
244244
className="mb-1.5"

www/apps/book/app/learn/page.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Below are some stories from companies that use Medusa:
7272

7373
This documentation introduces you to Medusa's concepts and how they help you build your business use case. The documentation is structured to gradually introduce Medusa's concepts, with easy-to-follow examples along the way.
7474

75-
By following this documentation, youll be able to create custom commerce experiences that would otherwise take large engineering teams months to build.
75+
By following this documentation, you'll be able to create custom commerce experiences that would otherwise take large engineering teams months to build.
7676

7777
### How to use the documentation
7878

www/apps/book/app/learn/storefront-development/page.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ You can build your storefront from scratch with your preferred tech stack, or st
1313
<CardList
1414
items={[
1515
{
16-
text: "Install Next.js Starter Storefront",
16+
title: "Install Next.js Starter Storefront",
1717
href: "!resources!/nextjs-starter"
1818
},
1919
{
20-
text: "Build Custom Storefront",
20+
title: "Build Custom Storefront",
2121
href: "!resources!/storefront-development"
2222
}
2323
]}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { getCleanMd } from "docs-utils"
2+
import { existsSync } from "fs"
3+
import { unstable_cache } from "next/cache"
4+
import { notFound } from "next/navigation"
5+
import { NextRequest, NextResponse } from "next/server"
6+
import path from "path"
7+
import {
8+
addUrlToRelativeLink,
9+
crossProjectLinksPlugin,
10+
localLinksRehypePlugin,
11+
} from "remark-rehype-plugins"
12+
import type { Plugin } from "unified"
13+
14+
type Params = {
15+
params: Promise<{ slug: string[] }>
16+
}
17+
18+
export async function GET(req: NextRequest, { params }: Params) {
19+
const { slug } = await params
20+
21+
// keep this so that Vercel keeps the files in deployment
22+
const basePath = path.join(process.cwd(), "app")
23+
const filePath = path.join(basePath, ...slug, "page.mdx")
24+
25+
if (!existsSync(filePath)) {
26+
return notFound()
27+
}
28+
29+
const cleanMdContent = await getCleanMd_(filePath, {
30+
before: [
31+
[
32+
crossProjectLinksPlugin,
33+
{
34+
baseUrl: process.env.NEXT_PUBLIC_BASE_URL,
35+
projectUrls: {
36+
resources: {
37+
url: process.env.NEXT_PUBLIC_RESOURCES_URL,
38+
},
39+
"user-guide": {
40+
url: process.env.NEXT_PUBLIC_RESOURCES_URL,
41+
},
42+
ui: {
43+
url: process.env.NEXT_PUBLIC_RESOURCES_URL,
44+
},
45+
api: {
46+
url: process.env.NEXT_PUBLIC_RESOURCES_URL,
47+
},
48+
},
49+
useBaseUrl:
50+
process.env.NODE_ENV === "production" ||
51+
process.env.VERCEL_ENV === "production",
52+
},
53+
],
54+
[localLinksRehypePlugin],
55+
] as unknown as Plugin[],
56+
after: [
57+
[addUrlToRelativeLink, { url: process.env.NEXT_PUBLIC_BASE_URL }],
58+
] as unknown as Plugin[],
59+
})
60+
61+
return new NextResponse(cleanMdContent, {
62+
headers: {
63+
"Content-Type": "text/markdown",
64+
},
65+
})
66+
}
67+
68+
const getCleanMd_ = unstable_cache(
69+
async (filePath: string, plugins?: { before?: Plugin[]; after?: Plugin[] }) =>
70+
getCleanMd({ filePath, plugins }),
71+
["clean-md"],
72+
{
73+
revalidate: 3600,
74+
}
75+
)

www/apps/book/middleware.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { NextResponse } from "next/server"
2+
import type { NextRequest } from "next/server"
3+
4+
export function middleware(request: NextRequest) {
5+
return NextResponse.rewrite(
6+
new URL(
7+
`/md-content${request.nextUrl.pathname.replace("/index.html.md", "")}`,
8+
request.url
9+
)
10+
)
11+
}
12+
13+
export const config = {
14+
matcher: "/:path*/index.html.md",
15+
}

www/apps/book/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@next/mdx": "15.0.4",
2121
"clsx": "^2.1.0",
2222
"docs-ui": "*",
23+
"docs-utils": "*",
2324
"next": "15.0.4",
2425
"react": "rc",
2526
"react-dom": "rc",
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import { getCleanMd } from "docs-utils"
2+
import { existsSync } from "fs"
3+
import { unstable_cache } from "next/cache"
4+
import { notFound } from "next/navigation"
5+
import { NextRequest, NextResponse } from "next/server"
6+
import path from "path"
7+
import {
8+
addUrlToRelativeLink,
9+
crossProjectLinksPlugin,
10+
localLinksRehypePlugin,
11+
} from "remark-rehype-plugins"
12+
import type { Plugin } from "unified"
13+
import { filesMap } from "../../../generated/files-map.mjs"
14+
import { slugChanges } from "../../../generated/slug-changes.mjs"
15+
16+
type Params = {
17+
params: Promise<{ slug: string[] }>
18+
}
19+
20+
export async function GET(req: NextRequest, { params }: Params) {
21+
const { slug = ["/"] } = await params
22+
23+
// keep this so that Vercel keeps the files in deployment
24+
path.join(process.cwd(), "app")
25+
path.join(process.cwd(), "references")
26+
27+
const filePathFromMap = await getFileFromMaps(`/${slug.join("/")}`)
28+
if (!filePathFromMap) {
29+
return notFound()
30+
}
31+
32+
const filePath = path.join(path.resolve("..", "..", ".."), filePathFromMap)
33+
34+
if (!existsSync(filePath)) {
35+
return notFound()
36+
}
37+
38+
const cleanMdContent = await getCleanMd_(filePath, {
39+
before: [
40+
[
41+
crossProjectLinksPlugin,
42+
{
43+
baseUrl: process.env.NEXT_PUBLIC_BASE_URL,
44+
projectUrls: {
45+
docs: {
46+
url: process.env.NEXT_PUBLIC_DOCS_URL,
47+
path: "",
48+
},
49+
"user-guide": {
50+
url: process.env.NEXT_PUBLIC_USER_GUIDE_URL,
51+
},
52+
ui: {
53+
url: process.env.NEXT_PUBLIC_UI_URL,
54+
},
55+
api: {
56+
url: process.env.NEXT_PUBLIC_API_URL,
57+
},
58+
},
59+
useBaseUrl:
60+
process.env.NODE_ENV === "production" ||
61+
process.env.VERCEL_ENV === "production",
62+
},
63+
],
64+
[localLinksRehypePlugin],
65+
] as unknown as Plugin[],
66+
after: [
67+
[addUrlToRelativeLink, { url: process.env.NEXT_PUBLIC_BASE_URL }],
68+
] as unknown as Plugin[],
69+
})
70+
71+
return new NextResponse(cleanMdContent, {
72+
headers: {
73+
"Content-Type": "text/markdown",
74+
},
75+
})
76+
}
77+
78+
const getCleanMd_ = unstable_cache(
79+
async (filePath: string, plugins?: { before?: Plugin[]; after?: Plugin[] }) =>
80+
getCleanMd({ filePath, plugins }),
81+
["clean-md"],
82+
{
83+
revalidate: 3600,
84+
}
85+
)
86+
87+
const getFileFromMaps = unstable_cache(
88+
async (path: string) => {
89+
return (
90+
slugChanges.find((slugChange) => slugChange.newSlug === path)?.filePath ||
91+
filesMap.find((file) => file.pathname === path)?.filePath
92+
)
93+
},
94+
["file-map"],
95+
{
96+
revalidate: 3600,
97+
}
98+
)

www/apps/resources/middleware.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { NextResponse } from "next/server"
2+
import type { NextRequest } from "next/server"
3+
4+
export function middleware(request: NextRequest) {
5+
return NextResponse.rewrite(
6+
new URL(
7+
`${request.nextUrl.basePath}/md-content${request.nextUrl.pathname.replace("/index.html.md", "")}`,
8+
request.url
9+
)
10+
)
11+
}
12+
13+
export const config = {
14+
matcher: "/:path*/index.html.md",
15+
}

www/apps/ui/contentlayer.config.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import "dotenv/config"
22

33
import { defineDocumentType, makeSource } from "contentlayer/source-files"
4-
import { rehypeComponent } from "./src/lib/rehype-component"
54
import rehypeSlug from "rehype-slug"
5+
import { uiRehypePlugin } from "../../packages/remark-rehype-plugins/src"
6+
import { ExampleRegistry } from "./src/registries/example-registry"
67

78
export const Doc = defineDocumentType(() => ({
89
name: "Doc",
@@ -29,7 +30,15 @@ export default makeSource({
2930
contentDirPath: "./src/content",
3031
documentTypes: [Doc],
3132
mdx: {
32-
rehypePlugins: [[rehypeComponent], [rehypeSlug]],
33+
rehypePlugins: [
34+
[
35+
uiRehypePlugin,
36+
{
37+
exampleRegistry: ExampleRegistry,
38+
},
39+
],
40+
[rehypeSlug],
41+
],
3342
mdxOptions: (options) => {
3443
return {
3544
...options,

www/apps/ui/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"contentlayer": "^0.3.4",
2525
"date-fns": "^3.3.1",
2626
"docs-ui": "*",
27+
"docs-utils": "*",
2728
"mdast-util-toc": "^7.0.0",
2829
"next": "15.0.4",
2930
"next-contentlayer": "^0.3.4",
@@ -47,6 +48,7 @@
4748
"eslint-plugin-prettier": "^5.2.1",
4849
"eslint-plugin-react-hooks": "^5.0.0",
4950
"react-docgen": "^7.1.0",
51+
"remark-rehype-plugins": "*",
5052
"ts-node": "^10.9.1",
5153
"types": "*"
5254
},

0 commit comments

Comments
 (0)