Skip to content

Commit 6174fd4

Browse files
authored
Merge pull request #41 from hasparus/new-landing--docs-tweaks
new landing — docs tweaks
2 parents 582aaa4 + 2755dfe commit 6174fd4

File tree

14 files changed

+563
-44
lines changed

14 files changed

+563
-44
lines changed

next.config.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
/* eslint-env node */
2+
// @ts-check
23

34
import nextra from "nextra"
45
import path from "node:path"
56
import withLess from "next-with-less"
67
import nextBundleAnalyzer from "@next/bundle-analyzer"
78
import fs from "fs"
9+
import rehypeMermaid from "rehype-mermaid"
810

911
import { remarkGraphiQLComment } from "./src/remark-graphiql-comment.js"
1012
import { syntaxHighlightingThemes } from "./src/_design-system/syntax/index.js"
@@ -17,6 +19,7 @@ const withNextra = nextra({
1719
themeConfig: "./theme.config.tsx",
1820
mdxOptions: {
1921
remarkPlugins: [remarkGraphiQLComment],
22+
rehypePlugins: [mermaidConfig()],
2023
rehypePrettyCodeOptions: {
2124
theme: syntaxHighlightingThemes,
2225
},
@@ -176,3 +179,37 @@ const withBundleAnalyzer = nextBundleAnalyzer({
176179
})
177180

178181
export default withBundleAnalyzer(withLess(withNextra(config)))
182+
183+
function mermaidConfig() {
184+
return [
185+
rehypeMermaid,
186+
/** @type {import("rehype-mermaid").RehypeMermaidOptions} */ ({
187+
mermaidConfig: {
188+
fontFamily: "var(--font-sans)", // we can't use monospace here because it's way too wide
189+
theme: "null",
190+
look: "classic",
191+
flowchart: {
192+
defaultRenderer: "elk",
193+
padding: 6,
194+
},
195+
themeCSS: `
196+
.node rect {
197+
fill: var(--mermaid-node-fill);
198+
stroke: var(--mermaid-node-stroke);
199+
}
200+
.label text, span {
201+
fill: hsl(var(--color-neu-900));
202+
color: hsl(var(--color-neu-900));
203+
}
204+
.flowchart-link {
205+
stroke: var(--mermaid-arrow);
206+
}
207+
.marker {
208+
stroke: var(--mermaid-arrow);
209+
fill: var(--mermaid-arrow);
210+
}
211+
`,
212+
},
213+
}),
214+
]
215+
}

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"@igorkowalczyk/is-browser": "^5.1.0",
2828
"@next/bundle-analyzer": "^15.4.5",
2929
"@radix-ui/react-radio-group": "^1.2.2",
30+
"@sparticuz/chromium": "^138.0.2",
3031
"@tailwindcss/container-queries": "^0.1.1",
3132
"@tailwindcss/nesting": "0.0.0-insiders.565cd3e",
3233
"@tailwindcss/typography": "^0.5.15",
@@ -57,12 +58,14 @@
5758
"numbro": "2.5.0",
5859
"p-limit": "^4.0.0",
5960
"parser-front-matter": "1.6.4",
61+
"playwright-core": "^1.54.2",
6062
"postcss": "^8.4.49",
6163
"postcss-import": "^16.1.1",
6264
"react": "^18.3.1",
6365
"react-dom": "^18.3.1",
6466
"react-medium-image-zoom": "5.2.13",
6567
"react-use-measure": "^2.1.7",
68+
"rehype-mermaid": "^3.0.0",
6669
"rss": "1.2.2",
6770
"server-only": "0.0.1",
6871
"string-similarity": "^4.0.4",
@@ -115,7 +118,9 @@
115118
],
116119
"pnpm": {
117120
"patchedDependencies": {
118-
"nextra": "patches/nextra.patch"
121+
"nextra": "patches/nextra.patch",
122+
"nextra-theme-docs": "patches/nextra-theme-docs.patch",
123+
"mermaid-isomorphic": "patches/mermaid-isomorphic.patch"
119124
}
120125
}
121126
}

patches/mermaid-isomorphic.patch

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
diff --git a/dist/mermaid-isomorphic.js b/dist/mermaid-isomorphic.js
2+
index aa5dc09a5dfb58a98d3f12cd2fc473caddd97b0d..d0fa3ca8e690233d0b50e4f992ab6ac33c11585b 100644
3+
--- a/dist/mermaid-isomorphic.js
4+
+++ b/dist/mermaid-isomorphic.js
5+
@@ -1,4 +1,5 @@
6+
-import { chromium } from 'playwright';
7+
+import { chromium as playwright } from 'playwright';
8+
+import chromium from '@sparticuz/chromium';
9+
const html = import.meta.resolve('../index.html');
10+
const mermaidScript = {
11+
url: import.meta.resolve('mermaid/dist/mermaid.js')
12+
@@ -7,6 +8,9 @@ const faStyle = {
13+
// We use url, not path. If we use path, the fonts can’t be resolved.
14+
url: import.meta.resolve('@fortawesome/fontawesome-free/css/all.css')
15+
};
16+
+
17+
+chromium.setGraphicsMode = false;
18+
+
19+
/* c8 ignore start */
20+
/**
21+
* Render mermaid diagrams in the browser.
22+
@@ -122,7 +126,21 @@ async function getBrowser(browserType, launchOptions) {
23+
* A function that renders Mermaid diagrams in the browser.
24+
*/
25+
export function createMermaidRenderer(options = {}) {
26+
- const { browserType = chromium, launchOptions } = options;
27+
+ let { browserType = playwright, launchOptions } = options;
28+
+
29+
+ if (process.env.CI) {
30+
+ if (options.browserType) {
31+
+ throw new Error('options.browserType is not supported because @hasparus patched it to run on Vercel builds, sorry');
32+
+ }
33+
+ browserType = {
34+
+ launch: async () => playwright.launch({
35+
+ ...launchOptions,
36+
+ args: chromium.args,
37+
+ executablePath: await chromium.executablePath(),
38+
+ })
39+
+ }
40+
+ }
41+
+
42+
let browserPromise;
43+
let count = 0;
44+
return async (diagrams, renderOptions) => {

patches/nextra-theme-docs.patch

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
diff --git a/dist/index.d.mts b/dist/index.d.mts
2+
index 71f87bcd1dde49d7c19ad49fc098e715a76c5c10..6671e29326be99861058895916185910452ced17 100644
3+
--- a/dist/index.d.mts
4+
+++ b/dist/index.d.mts
5+
@@ -1421,3 +1421,19 @@ declare function ThemeSwitch({ lite, className }: ThemeSwitchProps): ReactElemen
6+
declare function Layout({ children, themeConfig, pageOpts }: NextraThemeLayoutProps): ReactElement;
7+
8+
export { Bleed, Collapse, type PartialDocsThemeConfig as DocsThemeConfig, Link, LocaleSwitch, Navbar, NotFoundPage, SkipNavContent, SkipNavLink, ThemeSwitch, Layout as default, getComponents, useConfig, useMenu, useThemeConfig };
9+
+
10+
+export type ActiveAnchor = Record<
11+
+ string,
12+
+ {
13+
+ isActive?: boolean
14+
+ aboveHalfViewport: boolean
15+
+ index: number
16+
+ insideHalfViewport: boolean
17+
+ }
18+
+>
19+
+
20+
+export declare const useActiveAnchor: () => ActiveAnchor
21+
+export declare const useSetActiveAnchor: () => Dispatch<SetStateAction<ActiveAnchor>>
22+
+export declare const useIntersectionObserver: () => IntersectionObserver | null
23+
+export declare const useSlugs: () => WeakMap<any, any>
24+
+
25+
diff --git a/dist/index.js b/dist/index.js
26+
index 56201641fd965dcc5ab7c5df53e444c41293c00e..860b8cfd297e82da041c4d8287ed266691d75a0e 100644
27+
--- a/dist/index.js
28+
+++ b/dist/index.js
29+
@@ -100,10 +100,10 @@ IntersectionObserverContext.displayName = "IntersectionObserver";
30+
var slugs = /* @__PURE__ */ new WeakMap();
31+
var SlugsContext = createContext(slugs);
32+
SlugsContext.displayName = "Slugs";
33+
-var useActiveAnchor = () => useContext(ActiveAnchorContext);
34+
-var useSetActiveAnchor = () => useContext(SetActiveAnchorContext);
35+
-var useIntersectionObserver = () => useContext(IntersectionObserverContext);
36+
-var useSlugs = () => useContext(SlugsContext);
37+
+export var useActiveAnchor = () => useContext(ActiveAnchorContext);
38+
+export var useSetActiveAnchor = () => useContext(SetActiveAnchorContext);
39+
+export var useIntersectionObserver = () => useContext(IntersectionObserverContext);
40+
+export var useSlugs = () => useContext(SlugsContext);
41+
var ActiveAnchorProvider = ({
42+
children
43+
}) => {

patches/nextra.patch

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,28 @@ index 239d72f5921e2d1b7359e569ae5b74c12d7c9d8a..ebeb619da1e3ccb7722e9388c92c1e21
99
import { forwardRef } from "react";
1010
const Image = forwardRef((props, ref) => {
1111
const ComponentToUse = typeof props.src === "object" ? NextImage : "img";
12+
diff --git a/dist/client/components/index.js b/dist/client/components/index.js
13+
index 9d05118d3d10e746cd2c020785a0f34465bb8570..218107600d7efed1b5f9d49f0a696b166917d1ce 100644
14+
--- a/dist/client/components/index.js
15+
+++ b/dist/client/components/index.js
16+
@@ -14,7 +14,7 @@ import { Tabs } from "./tabs/index.js";
17+
import { Td } from "./td.js";
18+
import { Th } from "./th.js";
19+
import { Tr } from "./tr.js";
20+
-import { Mermaid } from "@theguild/remark-mermaid/mermaid";
21+
+// import { Mermaid } from "@theguild/remark-mermaid/mermaid";
22+
import { MathJax, MathJaxContext } from "better-react-mathjax";
23+
import { Playground } from "./playground.js";
24+
import { Popup } from "./popup.js";
25+
@@ -29,7 +29,7 @@ export {
26+
ImageZoom,
27+
MathJax,
28+
MathJaxContext,
29+
- Mermaid,
30+
+ // Mermaid, // disabled to use rehype-mermaid and remove cytoscape from the bundle
31+
Playground,
32+
Popup,
33+
Pre,
1234
diff --git a/dist/client/normalize-pages.js b/dist/client/normalize-pages.js
1335
index 15afee0c1de26f47d781f423e5ec32e33ad925d3..fefd01736bd2b778df275bf50ac48384d5f63845 100644
1436
--- a/dist/client/normalize-pages.js
@@ -24,3 +46,24 @@ index 15afee0c1de26f47d781f423e5ec32e33ad925d3..fefd01736bd2b778df275bf50ac48384
2446
if (!isValid) {
2547
throw new Error(
2648
`Validation of "_meta" file has failed.
49+
diff --git a/dist/server/compile.js b/dist/server/compile.js
50+
index c266efec3fe344a81c6d5791b93ab1b2bd268782..4866148a725800ef2326732f78807cca0f04cb7b 100644
51+
--- a/dist/server/compile.js
52+
+++ b/dist/server/compile.js
53+
@@ -1,6 +1,6 @@
54+
import path from "path";
55+
import { createProcessor } from "@mdx-js/mdx";
56+
-import { remarkMermaid } from "@theguild/remark-mermaid";
57+
+// import { remarkMermaid } from "@theguild/remark-mermaid";
58+
import { remarkNpm2Yarn } from "@theguild/remark-npm2yarn";
59+
import rehypeKatex from "rehype-katex";
60+
import rehypePrettyCode from "rehype-pretty-code";
61+
@@ -143,7 +143,7 @@ async function compileMdx(source, {
62+
development: process.env.NODE_ENV === "development",
63+
remarkPlugins: [
64+
...remarkPlugins || [],
65+
- remarkMermaid,
66+
+ // remarkMermaid, // disabled to use rehype-mermaid and remove cytoscape from the bundle
67+
// should be before remarkRemoveImports because contains `import { Mermaid } from ...`
68+
[
69+
remarkNpm2Yarn,

0 commit comments

Comments
 (0)