Skip to content

Commit 216603d

Browse files
committed
fix: resolve merge conflicts with master
2 parents d75209d + 1bc5605 commit 216603d

7 files changed

Lines changed: 153 additions & 31 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
env:
5454
VITE_DEPLOYMENT_URL: ${{ env.VITE_DEPLOYMENT_URL }}
5555
- name: Deploy
56+
if: ${{ github.actor != 'dependabot[bot]' }}
5657
id: deploy
5758
uses: cloudflare/wrangler-action@v3
5859
with:
@@ -64,6 +65,7 @@ jobs:
6465
env:
6566
FORCE_COLOR: 0
6667
- name: Comment PR with deployment link
68+
if: ${{ github.actor != 'dependabot[bot]' }}
6769
uses: marocchino/sticky-pull-request-comment@v2
6870
with:
6971
recreate: true

app/routes.res

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,21 @@ let docsManualRoutes =
3838
->Array.filter(path => !String.includes(path, "docs/manual/api"))
3939
->Array.map(path => route(path, "./routes/DocsManualRoute.jsx", ~options={id: path}))
4040

41+
let communityRoutes =
42+
MdxFile.scanPaths(~dir="markdown-pages/community", ~alias="community")->Array.map(path =>
43+
route(path, "./routes/CommunityRoute.jsx", ~options={id: path})
44+
)
45+
4146
let mdxRoutes = mdxRoutes("./routes/MdxRoute.jsx")->Array.filter(r =>
4247
!(
4348
r.path
4449
->Option.map(path =>
4550
path === "blog" ||
4651
String.startsWith(path, "blog/") ||
47-
((path === "docs/manual" || String.startsWith(path, "docs/manual/")) &&
48-
path !== "docs/manual/api")
52+
(path === "docs/manual" || String.startsWith(path, "docs/manual/")) &&
53+
path !== "docs/manual/api" ||
54+
path === "community" ||
55+
String.startsWith(path, "community/")
4956
)
5057
->Option.getOr(false)
5158
)
@@ -67,6 +74,7 @@ let default = [
6774
...beltRoutes,
6875
...blogArticleRoutes,
6976
...docsManualRoutes,
77+
...communityRoutes,
7078
...mdxRoutes,
7179
route("*", "./routes/NotFoundRoute.jsx"),
7280
]

app/routes/CommunityRoute.res

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
type loaderData = {
2+
compiledMdx: CompiledMdx.t,
3+
entries: array<TableOfContents.entry>,
4+
title: string,
5+
description: string,
6+
filePath: string,
7+
categories: array<SidebarLayout.Sidebar.Category.t>,
8+
}
9+
10+
let convertToNavItems = (items, rootPath) =>
11+
Array.map(items, (item): SidebarLayout.Sidebar.NavItem.t => {
12+
let href = switch item.Mdx.slug {
13+
| Some(slug) => `${rootPath}/${slug}`
14+
| None => rootPath
15+
}
16+
{
17+
name: item.title,
18+
href,
19+
}
20+
})
21+
22+
let getGroup = (groups, groupName): SidebarLayout.Sidebar.Category.t => {
23+
{
24+
name: groupName,
25+
items: groups
26+
->Dict.get(groupName)
27+
->Option.getOr([]),
28+
}
29+
}
30+
31+
let getAllGroups = (groups, groupNames): array<SidebarLayout.Sidebar.Category.t> =>
32+
groupNames->Array.map(item => getGroup(groups, item))
33+
34+
let communityTableOfContents = async () => {
35+
let groups =
36+
(await Mdx.allMdx(~filterByPaths=["markdown-pages/community"]))
37+
->Mdx.filterMdxPages("community")
38+
->Mdx.groupBySection
39+
->Dict.mapValues(values => values->Mdx.sortSection->convertToNavItems("/community"))
40+
41+
getAllGroups(groups, ["Resources"])
42+
}
43+
44+
let loader: ReactRouter.Loader.t<loaderData> = async ({request}) => {
45+
let {pathname} = WebAPI.URL.make(~url=request.url)
46+
let filePath = MdxFile.resolveFilePath(
47+
(pathname :> string),
48+
~dir="markdown-pages/community",
49+
~alias="community",
50+
)
51+
52+
let raw = await Node.Fs.readFile(filePath, "utf-8")
53+
let {frontmatter}: MarkdownParser.result = MarkdownParser.parseSync(raw)
54+
55+
let description = switch frontmatter {
56+
| Object(dict) =>
57+
switch dict->Dict.get("description") {
58+
| Some(String(s)) => s
59+
| _ => ""
60+
}
61+
| _ => ""
62+
}
63+
64+
let title = switch frontmatter {
65+
| Object(dict) =>
66+
switch dict->Dict.get("title") {
67+
| Some(String(s)) => s
68+
| _ => ""
69+
}
70+
| _ => ""
71+
}
72+
73+
let compiledMdx = await MdxFile.compileMdx(raw, ~filePath, ~remarkPlugins=Mdx.plugins)
74+
75+
let markdownTree = Mdast.fromMarkdown(raw)
76+
let tocResult = Mdast.toc(markdownTree, {maxDepth: 2})
77+
78+
let headers = Dict.make()
79+
Mdast.reduceHeaders(tocResult.map, headers)
80+
81+
let entries =
82+
headers
83+
->Dict.toArray
84+
->Array.map(((header, url)): TableOfContents.entry => {
85+
header,
86+
href: (url :> string),
87+
})
88+
->Array.slice(~start=2)
89+
90+
let categories = await communityTableOfContents()
91+
92+
{
93+
compiledMdx,
94+
entries,
95+
title: `${title} | ReScript Community`,
96+
description,
97+
filePath,
98+
categories,
99+
}
100+
}
101+
102+
let default = () => {
103+
let {compiledMdx, entries, filePath, categories} = ReactRouter.useLoaderData()
104+
105+
let editHref = `https://github.com/rescript-lang/rescript-lang.org/blob/master/${filePath}`
106+
107+
<>
108+
<CommunityLayout categories entries>
109+
<div className="markdown-body">
110+
<MdxContent compiledMdx />
111+
</div>
112+
<a
113+
href=editHref className="inline text-14 hover:underline text-fire" rel="noopener noreferrer"
114+
>
115+
{React.string("Edit")}
116+
</a>
117+
</CommunityLayout>
118+
</>
119+
}

app/routes/CommunityRoute.resi

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
type loaderData = {
2+
compiledMdx: CompiledMdx.t,
3+
entries: array<TableOfContents.entry>,
4+
title: string,
5+
description: string,
6+
filePath: string,
7+
categories: array<SidebarLayout.Sidebar.Category.t>,
8+
}
9+
10+
let loader: ReactRouter.Loader.t<loaderData>
11+
12+
let default: unit => React.element

app/routes/MdxRoute.res

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,6 @@ let reactTableOfContents = async () => {
7979
categories
8080
}
8181

82-
let communityTableOfContents = async () => {
83-
let groups =
84-
(await allMdx(~filterByPaths=["markdown-pages/community"]))
85-
->filterMdxPages("community")
86-
->groupBySection
87-
->Dict.mapValues(values => values->sortSection->convertToNavItems("/community"))
88-
89-
// these are the categories that appear in the sidebar
90-
let categories: array<SidebarLayout.Sidebar.Category.t> = SidebarHelpers.getAllGroups(
91-
groups,
92-
["Resources"],
93-
)
94-
95-
categories
96-
}
97-
9882
let loader: ReactRouter.Loader.t<loaderData> = async ({request}) => {
9983
let {pathname} = WebAPI.URL.make(~url=request.url)
10084

@@ -130,8 +114,6 @@ let loader: ReactRouter.Loader.t<loaderData> = async ({request}) => {
130114
[]
131115
} else if pathname->String.includes("docs/react") {
132116
await reactTableOfContents()
133-
} else if pathname->String.includes("community") {
134-
await communityTableOfContents()
135117
} else {
136118
[]
137119
}
@@ -195,8 +177,8 @@ let loader: ReactRouter.Loader.t<loaderData> = async ({request}) => {
195177
"ReScript React"
196178
} else if path->String.includes("docs/manual/api") {
197179
"ReScript API"
198-
} else if path->String.includes("community") {
199-
"ReScript Community"
180+
} else if path->String.includes("docs/manual") {
181+
"ReScript Language Manual"
200182
} else {
201183
"ReScript"
202184
}
@@ -354,10 +336,6 @@ let default = () => {
354336
</>
355337
}
356338
</>
357-
} else if (pathname :> string)->String.includes("community") {
358-
<CommunityLayout categories entries>
359-
<div className="markdown-body"> {component()} </div>
360-
</CommunityLayout>
361339
} else {
362340
switch loaderData.mdxSources {
363341
| Some(mdxSources) =>

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@
8282
"unified": "^11.0.5",
8383
"vfile-matter": "^5.0.1"
8484
},
85+
"resolutions": {
86+
"marked": "4.0.10"
87+
},
8588
"devDependencies": {
8689
"@prettier/plugin-oxc": "^0.1.3",
8790
"@react-router/dev": "^7.14.0",

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6635,12 +6635,12 @@ __metadata:
66356635
languageName: node
66366636
linkType: hard
66376637

6638-
"marked@npm:^0.3.14":
6639-
version: 0.3.19
6640-
resolution: "marked@npm:0.3.19"
6638+
"marked@npm:4.0.10":
6639+
version: 4.0.10
6640+
resolution: "marked@npm:4.0.10"
66416641
bin:
6642-
marked: ./bin/marked
6643-
checksum: 10c0/ee5e268716de56a7543c245268d72e5eb1a66f67022e0392cab9744b3b38768d1db289c173679ff696cdbf1bcd82ff10520cae2296f3293989e07a17f9218705
6642+
marked: bin/marked.js
6643+
checksum: 10c0/137660cd1eca54cfcdcec9d9c7dea786fc57ba3663da9043b721aff4c1419fc869d21bc38f6d5907062b82d4ef354f4fcac6605cac5f4f9dc1595a743b856d91
66446644
languageName: node
66456645
linkType: hard
66466646

0 commit comments

Comments
 (0)