Skip to content

Commit 5631852

Browse files
jderochervlkCopilottsnobip
authored
refactor: switch to React Router (#1115)
* refactor: switch to React Router * refactor: add order and section to language manual frontmatter * add react * improve css loading speed * fix fouc * fix css not loading * make sure progress is synced * language manual * working on tables * back out table changes for now * updating blog pages * builds are working * copy to out folder * add static server * cleanup some deps * cleanup some todo comments * configure loadmdx * tables looking good * more mdx work * move react docs * react docs and anchor scrolling * fixed scrolling on full page nav * api is rendering * api prerender is working * working on api table of contents * Initial plan * Migrate CodeMirror from v5 to v6 - initial implementation Co-authored-by: tsnobip <2479216+tsnobip@users.noreply.github.com> * Fix warnings and remove CodeMirror v5 dependency Co-authored-by: tsnobip <2479216+tsnobip@users.noreply.github.com> * Address code review feedback - fix import paths, error handling, and add documentation Co-authored-by: tsnobip <2479216+tsnobip@users.noreply.github.com> * Fix error validation logic - properly validate both line and column bounds Co-authored-by: tsnobip <2479216+tsnobip@users.noreply.github.com> * Clarify error position indexing in comments - rows are 1-based, columns are 0-based Co-authored-by: tsnobip <2479216+tsnobip@users.noreply.github.com> * Fix ReferenceError: createEditor is not defined - call function directly instead of wrapping in %raw Co-authored-by: tsnobip <2479216+tsnobip@users.noreply.github.com> * Format JavaScript files with Prettier Co-authored-by: tsnobip <2479216+tsnobip@users.noreply.github.com> * Convert createEditor from raw JavaScript to native ReScript with comprehensive bindings Co-authored-by: tsnobip <2479216+tsnobip@users.noreply.github.com> * apidocs * use more idiomatic rescript bindings * api nav is working * trying to fix the inline codeblock * just remove it for now * fix & * move syntax pages * working on blog listing page * working on syntax page * blog listing page is mostly working * update to rc.2 * blog post is rendering * fix archived blog posts * static builds are working * rendering community pages * getting close * package search * syntax lookup * remove package-lock * rebuild package lock * fix webapi * fixes * control panel * fix divider * more cleanup * more style fixes * config cleanup * delete pages folder * rebuild package lock and remove .nvmrc * try fixing missing types * add search * use npm build * fix typo * fix package lock webapi version * run formatter * rollback codemirror * back to codemirror 5 * Revert "use more idiomatic rescript bindings" This reverts commit 1213a43. * back to codemirror 5 * Revert "rollback codemirror" This reverts commit ba425b2. * playground is working * fix background color on dropdown * warning table * docson * fixed markdown * import css * remove trailing ; * add back tests * fix doc tests * remove href test * test out redirects * formatting * add 404 page * typo in redirects * fix filename * fix prettier ignore * preconnect to css * fix flicker * fix community link * Fix community links * fix search box and docson * getting meta tags to work * meta tags * fix image imports after merge * formatting * align naming for Lazy components * add scroll lock and fix mobile nav bar * fix edit link * close mobile navbar and disable scroll lock on navigation * fix non doc page mobile nav * fix syntax lookup url * pr feedback * clean up todos * fix community navbar * add belt and dom apis to docs * remove index data * fix sidebar top padding * add --host to dev command * move markdown files into shared folder * fix api path * cleanup console logs * fix unregistered languages * format * improve search results box * remove console log * format * fix breadcrumb links * fix bindings to lzstring * fix doc links to playground * add env variables for branch and deployment url * fix benchmark image * update links to remove /latest/ and add full v11 domain for older links * remove .mdx extensions from mdx file links * fix anchor tags * remove link to Js lib * fix llm * fix scripts * add more to build command * remove generate resources command * fix branch * fix anchor tags for same page * remove branch * links to api/core changed to api/stdlib * remove VERSION * llm link fixes * format * remove link to unboxed record * add resi files * add docs page * fix api trailing slash and installation table * remove console log * prettier ignore installation page * run rescript first in build * format package.json * rename blogposts to blog * fix routes and work on route testing * remove data from blog post * remove archived dates * fix mdx links * fix more md links * fix hrefs in markdown and add testing and CI failures * fix more links and add errors on invalid links * more fixes * fix more links * format again * fix template * rescript first in build * ignore blog warning * remove tests form build since they happen in CI * simplify build * try and log different information * try pushing through error * run patch-package before build because of cloudflare * fix reanalyze links * normalize h3-h5 * restore warnings * fix warnings * remove mention of core behavior * fix link to promise docs * sort blog posts by date * tidying up * pr feedback * format * fix getting wrong ToC * fix anchor links * fix logo link to use react router link * add preloading and prefetching * more prefetch on intent * fix llm.txt links * format * format --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tsnobip <2479216+tsnobip@users.noreply.github.com> Co-authored-by: tsnobip <dontshootthink@gmail.com>
1 parent 6c59476 commit 5631852

File tree

1,138 files changed

+22505
-200345
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,138 files changed

+22505
-200345
lines changed

.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
VERSION_LATEST="v11.0.0"
2-
VERSION_NEXT="v12.0.0"
1+
VITE_VERSION_LATEST="v11.0.0"
2+
VITE_VERSION_NEXT="v12.0.0"

.github/workflows/pull-request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ jobs:
1010
node-version-file: ".node-version"
1111
cache: npm
1212
- run: npm ci
13-
- run: npx rescript
13+
- run: npm run res:build
1414
- run: npm test
1515
- run: npm run ci:format

.gitignore

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ index_data/*.json
1414
_tempFile.cmi
1515
_tempFile.cmj
1616
_tempFile.cmt
17-
18-
# these docs are checked in, but we consider them frozen.
19-
# pages/docs/manual/v8.0.0/
20-
# pages/docs/manual/v9.0.0/
17+
_tempFile.res
18+
temp
2119

2220
.bsb.lock
2321
.merlin
@@ -35,4 +33,13 @@ public/llms/react/**/llm*.txt
3533
pages/docs/**/**/llms.mdx
3634

3735
public/playground-bundles/
38-
public/_redirects
36+
!public/_redirects
37+
38+
39+
dist
40+
build
41+
.react-router
42+
mdx-manifest.json
43+
44+
app/**/*.mjs
45+
!_shims.mjs

.node-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
22.11.0
1+
22.16.0

.prettierignore

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,49 @@
11
data/api/**/*.json
2+
3+
.DS_Store
4+
*.swp
5+
*.swo
6+
7+
# Generated via update-index script
8+
public/blog/feed.xml
9+
10+
node_modules/
11+
.next/
12+
out/
13+
index_data/*.json
14+
15+
# Generated via test examples script
16+
_tempFile.cmi
17+
_tempFile.cmj
18+
_tempFile.cmt
19+
_tempFile.res
20+
temp
21+
22+
.bsb.lock
23+
.merlin
24+
lib/
25+
26+
.vercel
27+
28+
src/**/*.mjs
29+
scripts/gendocs.mjs
30+
scripts/generate_*.mjs
31+
32+
# Generated via generate-llms script
33+
public/llms/manual/**/llm*.txt
34+
public/llms/react/**/llm*.txt
35+
pages/docs/**/**/llms.mdx
36+
37+
public/playground-bundles/
38+
!public/_redirects
39+
40+
41+
dist
42+
build
43+
.react-router
44+
45+
app/**/*.mjs
46+
!_shims.mjs
47+
48+
# prettier refuses to not mess up the installation table
49+
markdown-pages/docs/manual/installation.mdx

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ In case you are a blog author, please refer to our [guide on writing blog posts]
153153
In case your company is a user of ReScript and wants to be displayed on our front page ("Trusted by our users" section), do the following:
154154

155155
- Get your logo as a black / white `.svg` version and use `#979AAD` as a fill color (check out the existing logos on our front page).
156-
- Put your logo into the [`public/static/lp`](./public/static/lp) folder; the file should be named after your company.
156+
- Put your logo into the [`app/public/lp`](./app/public/lp) folder; the file should be named after your company.
157157
- Open [src/common/OurUsers.res](./src/common/OurUsers.res) and add your info
158158
- Commit, push, and open a PR.
159159

app/root.res

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
@module("../styles/main.css?url")
2+
external mainCss: string = "default"
3+
4+
@module("../styles/_hljs.css?url")
5+
external hljsCss: string = "default"
6+
7+
@module("../styles/utils.css?url")
8+
external utilsCss: string = "default"
9+
10+
%%raw(`
11+
import hljs from 'highlight.js/lib/core';
12+
import bash from 'highlight.js/lib/languages/bash';
13+
import css from 'highlight.js/lib/languages/css';
14+
import diff from 'highlight.js/lib/languages/diff';
15+
import javascript from 'highlight.js/lib/languages/javascript';
16+
import typescript from 'highlight.js/lib/languages/typescript';
17+
import json from 'highlight.js/lib/languages/json';
18+
import text from 'highlight.js/lib/languages/plaintext';
19+
import html from 'highlight.js/lib/languages/xml';
20+
import toml from 'highlight.js/lib/languages/ini';
21+
import rescript from 'highlightjs-rescript';
22+
23+
hljs.registerLanguage('rescript', rescript)
24+
hljs.registerLanguage('javascript', javascript)
25+
hljs.registerLanguage('css', css)
26+
hljs.registerLanguage('ts', typescript)
27+
hljs.registerLanguage('sh', bash)
28+
hljs.registerLanguage('bash', bash)
29+
hljs.registerLanguage('toml', toml)
30+
hljs.registerLanguage('json', json)
31+
hljs.registerLanguage('text', text)
32+
hljs.registerLanguage('html', html)
33+
hljs.registerLanguage('diff', diff)
34+
hljs.registerLanguage('typescript', typescript)
35+
`)
36+
37+
open ReactRouter
38+
39+
@react.component
40+
let default = () => {
41+
let {pathname} = ReactRouter.useLocation()
42+
let (isOverlayOpen, setOverlayOpen) = React.useState(_ => false)
43+
let (isScrollLockEnabled, setIsScrollLockEnabled) = React.useState(_ => false)
44+
45+
React.useEffect(() => {
46+
// When the path changes close the sidebar and disable scroll lock
47+
setOverlayOpen(_ => false)
48+
setIsScrollLockEnabled(_ => false)
49+
None
50+
}, [pathname])
51+
52+
<html>
53+
<head>
54+
<style> {React.string("html {opacity:0;}")} </style>
55+
<link rel="preload" href={mainCss} as_="css" />
56+
// Preload the fonts used for the above the fold on the homepage
57+
<link rel="preload" href="/fonts/subset-Inter-Bold.woff2" as_="font" />
58+
<link rel="preload" href="/fonts/subset-Inter-Regular.woff2" as_="font" />
59+
<link rel="stylesheet" href={mainCss} />
60+
61+
<Links />
62+
<Meta />
63+
<link rel="stylesheet" href={hljsCss} />
64+
<link rel="stylesheet" href={utilsCss} />
65+
<link rel="icon" href="/favicon.ico" />
66+
<meta
67+
name="viewport"
68+
content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, minimal-ui"
69+
/>
70+
<meta charSet="UTF-8" />
71+
</head>
72+
<body className={isScrollLockEnabled ? "overflow-hidden" : ""}>
73+
<ScrollLockContext.Provider lockState=(isScrollLockEnabled, setIsScrollLockEnabled)>
74+
<EnableCollapsibleNavbar isEnabled={!isOverlayOpen}>
75+
<Navigation isOverlayOpen setOverlayOpen />
76+
<Outlet />
77+
<ScrollRestoration />
78+
<Scripts />
79+
</EnableCollapsibleNavbar>
80+
</ScrollLockContext.Provider>
81+
</body>
82+
</html>
83+
}

app/root.resi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@react.component
2+
let default: unit => Jsx.element

app/routes.res

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
open ReactRouter.Routes
2+
3+
let stdlibPaths = {
4+
let rawFile = await Node.Fs.readFile("./markdown-pages/docs/api/stdlib.json", "utf-8")
5+
let json = JSON.parseOrThrow(rawFile)
6+
switch json {
7+
| Object(json) => Dict.keysToArray(json)
8+
| _ => []
9+
}
10+
->Array.map(key => "docs/manual/api/" ++ key)
11+
->Array.filter(path => path !== "docs/manual/api/stdlib")
12+
}
13+
14+
let beltPaths = {
15+
let rawFile = await Node.Fs.readFile("./markdown-pages/docs/api/belt.json", "utf-8")
16+
let json = JSON.parseOrThrow(rawFile)
17+
switch json {
18+
| Object(json) => Dict.keysToArray(json)
19+
| _ => []
20+
}
21+
->Array.map(key => "docs/manual/api/" ++ key)
22+
->Array.filter(path => path !== "docs/manual/api/belt")
23+
}
24+
25+
let stdlibRoutes =
26+
stdlibPaths->Array.map(path => route(path, "./routes/ApiRoute.mjs", ~options={id: path}))
27+
28+
let beltRoutes =
29+
beltPaths->Array.map(path => route(path, "./routes/ApiRoute.mjs", ~options={id: path}))
30+
31+
let default = [
32+
index("./routes/LandingPageRoute.mjs"),
33+
route("packages", "./routes/PackagesRoute.mjs"),
34+
route("try", "./routes/TryRoute.mjs"),
35+
route("syntax-lookup", "./routes/SyntaxLookupRoute.mjs", ~options={id: "syntax-lookup"}),
36+
route("blog", "./routes/BlogRoute.mjs", ~options={id: "blog-index"}),
37+
route("blog/archived", "./routes/BlogRoute.mjs", ~options={id: "blog-archived"}),
38+
route("docs", "./routes/DocsOverview.mjs", ~options={id: "docs-overview"}),
39+
route("docs/manual/api/stdlib", "./routes/ApiRoute.mjs", ~options={id: "api-stdlib"}),
40+
route("docs/manual/api/introduction", "./routes/ApiRoute.mjs", ~options={id: "api-intro"}),
41+
route("docs/manual/api/belt", "./routes/ApiRoute.mjs", ~options={id: "api-belt"}),
42+
route("docs/manual/api/dom", "./routes/ApiRoute.mjs", ~options={id: "api-dom"}),
43+
...stdlibRoutes,
44+
...beltRoutes,
45+
...mdxRoutes("./routes/MdxRoute.mjs"),
46+
route("*", "./routes/NotFoundRoute.mjs"),
47+
]

app/routes.resi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
let stdlibPaths: array<string>
2+
let beltPaths: array<string>
3+
let stdlibRoutes: array<ReactRouter.Routes.t>
4+
let beltRoutes: array<ReactRouter.Routes.t>
5+
let default: Belt.Array.t<ReactRouter.Routes.t>

0 commit comments

Comments
 (0)