Skip to content

Commit 1b67d8f

Browse files
authored
Merge branch 'main' into hien
2 parents 4b9274c + e083c25 commit 1b67d8f

File tree

9 files changed

+950
-162
lines changed

9 files changed

+950
-162
lines changed

astro.config.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export default defineConfig({
4949
],
5050
},
5151
}),
52+
mermaid(),
5253
],
5354
prefetch: {
5455
defaultStrategy: "viewport",
@@ -80,5 +81,6 @@ export default defineConfig({
8081
shikiConfig: {
8182
theme: 'github-light',
8283
},
84+
8385
},
8486
});

package-lock.json

Lines changed: 855 additions & 129 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"@typescript-eslint/parser": "^7.0.2",
7070
"@uiw/codemirror-extensions-basic-setup": "^4.21.22",
7171
"@uiw/react-codemirror": "^4.21.22",
72+
"astro-mermaid": "^1.1.0",
7273
"documentation": "^14.0.3",
7374
"eslint": "^8.56.0",
7475
"eslint-config-preact": "^1.3.0",
@@ -84,10 +85,12 @@
8485
"jsdom": "^24.0.0",
8586
"log-update": "^6.1.0",
8687
"marked": "^4.0.10",
88+
"mermaid": "^11.12.1",
8789
"msw": "^2.2.9",
8890
"path": "^0.12.7",
8991
"prettier": "^3.2.5",
9092
"prettier-plugin-tailwindcss": "^0.5.11",
93+
"rehype-mermaid": "^3.0.0",
9194
"remark": "^15.0.1",
9295
"remark-gfm": "^4.0.0",
9396
"remark-mdx": "^3.0.1",

src/content/contributor-docs/en/webgl_mode_architecture.mdx

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -228,33 +228,27 @@ It also has the following per-vertex attributes:
228228

229229
## Classes
230230

231+
<h4 align="center"><small>p5.js WebGL Classes</small></h4>
232+
231233
```mermaid
232-
---
233-
title: p5.js WebGL Classes
234-
---
235234
classDiagram
236-
class Base["p5.Renderer"] {
237-
}
238-
class P2D["p5.Renderer2D"] {
239-
}
240-
class WebGL["p5.RendererGL"] {
241-
}
242-
class Geometry["p5.Geometry"] {
243-
}
244-
class Shader["p5.Shader"] {
245-
}
246-
class Texture["p5.Texture"] {
247-
}
248-
class Framebuffer["p5.Framebuffer"] {
249-
}
250-
Base <|-- P2D
251-
Base <|-- WebGL
252-
WebGL "*" o-- "*" Geometry
253-
WebGL "1" *-- "*" Shader
254-
WebGL "1" *-- "*" Texture
255-
WebGL "1" *-- "*" Framebuffer
235+
class Base["p5.Renderer"]
236+
class P2D["p5.Renderer2D"]
237+
class WebGL["p5.RendererGL"]
238+
class Geometry["p5.Geometry"]
239+
class Shader["p5.Shader"]
240+
class Texture["p5.Texture"]
241+
class Framebuffer["p5.Framebuffer"]
242+
243+
Base <|-- P2D
244+
Base <|-- WebGL
245+
WebGL "1" *-- "*" Geometry
246+
WebGL "1" *-- "*" Shader
247+
WebGL "1" *-- "*" Texture
248+
WebGL "1" *-- "*" Framebuffer
256249
```
257250

251+
258252
The entry point to most WebGL code is through **p5.RendererGL**. Top-level p5.js functions are passed to the current renderer. Both 2D and WebGL modes have renderer classes that conform to a common `p5.Renderer` interface. Immediate mode and retained mode functions are split up into `p5.RendererGL.Immediate.js` and `p5.RendererGL.Retained.js`.
259253

260254
Within the renderer, references to models are stored in the `retainedMode.geometry` map. Each value is an object storing the buffers of a `p5.Geometry` When calling `model(yourGeometry)` for the first time, the renderer adds an entry in the map. It then stores references to the geometry's GPU resources there. If you draw a `p5.Geometry` to the main canvas and also to a WebGL `p5.Graphics`, it will have entries in two renderers.

src/content/tutorials/en/get-started.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ relatedContent:
1616
authors:
1717
- Layla Quiñones
1818
- Jaleesa Trapp
19+
1920
---
2021

2122
import EditableSketch from "../../../components/EditableSketch/index.astro";
@@ -44,6 +45,17 @@ Before you begin you should be able to:
4445

4546
For a step-by-step guide to creating and saving projects in the [p5.js Web Editor](https://editor.p5js.org/) or [VS Code](https://code.visualstudio.com/), visit [Setting Up Your Environment](../setting-up-your-environment).
4647

48+
# Mermaid test
49+
50+
<div className="mermaid">
51+
{String.raw`flowchart TD
52+
A[Start] --> B{Build-time Mermaid?}
53+
B -- Yes --> C[Inline SVG ✅]
54+
B -- No --> D[Code block ❌]
55+
`}
56+
</div>
57+
58+
4759

4860
## Step 1: Name and save a new p5.js project
4961

@@ -77,6 +89,7 @@ function setup() {
7789
function draw() {
7890
  background(220);
7991
}
92+
8093
```
8194

8295
Every sketch.js file begins with two main functions: [`setup()`](/reference/p5/setup) and [`draw()`](/reference/p5/draw)

src/env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/* eslint-disable @typescript-eslint/triple-slash-reference */
22
/// <reference path="../.astro/types.d.ts" />
33
/// <reference types="astro/client" />
4+
/// <reference types="astro/client" />

src/layouts/BaseLayout.astro

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const headerTopic = topic
6767
lang={currentLocale}
6868
>
6969
<head>
70+
<script src="https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js"></script>
7071
<script is:inline>
7172
// Get any theme settings and apply before load
7273
const settings = [
@@ -88,9 +89,9 @@ const headerTopic = topic
8889
rel="stylesheet"
8990
href="https://foundation-donate-banner.netlify.app/static/css/main.css"
9091
/>
91-
<script src="https://foundation-donate-banner.netlify.app/static/js/main.js"
92-
></script>
92+
<script src="https://foundation-donate-banner.netlify.app/static/js/main.js"></script>
9393
</head>
94+
9495
<body>
9596
<div class="top-layout-grid">
9697
<Nav />
@@ -117,18 +118,64 @@ const headerTopic = topic
117118
}
118119
</header>
119120
<main id="main-content" class="relative">
120-
<div id="processing-banner" style="margin-left: var(--nav-offset-x);">
121-
</div>
121+
<div id="processing-banner" style="margin-left: var(--nav-offset-x);"></div>
122122
{
123123
HeaderContent && (
124124
<div class="px-5 md:px-lg pt-sm pb-lg">
125125
<div class="rendered-markdown">
126126
<HeaderContent />
127127
</div>
128128
</div>
129-
)}
129+
)
130+
}
130131
<div class={mainContentParentClass}>
131132
<slot />
133+
<script>
134+
function extractMermaid(text) {
135+
// strip YAML front-matter if present
136+
if (text.startsWith('---')) {
137+
const parts = text.split('\n');
138+
let i = 1;
139+
while (i < parts.length && parts[i] !== '---') i++;
140+
if (i < parts.length) text = parts.slice(i + 1).join('\n');
141+
}
142+
return text.trim();
143+
}
144+
145+
function renderMermaid() {
146+
// 1) Convert fenced code blocks that look like Mermaid
147+
const mermaidHeads = new Set([
148+
'classDiagram','flowchart','graph','sequenceDiagram','stateDiagram',
149+
'erDiagram','journey','pie','gantt','mindmap','timeline','quadrantChart',
150+
'requirementDiagram','gitGraph'
151+
]);
152+
153+
const codeBlocks = document.querySelectorAll('pre code');
154+
codeBlocks.forEach((codeEl) => {
155+
const raw = extractMermaid(codeEl.textContent || '');
156+
const first = raw.split(/\s+/)[0];
157+
const isMermaid = codeEl.className.includes('language-mermaid') || mermaidHeads.has(first);
158+
if (!isMermaid) return;
159+
160+
const pre = codeEl.closest('pre');
161+
const div = document.createElement('div');
162+
div.className = 'mermaid';
163+
div.textContent = raw; // pure Mermaid only
164+
if (pre && pre.parentNode) pre.parentNode.replaceChild(div, pre);
165+
});
166+
167+
// 2) Render any <div class="mermaid"> now on the page
168+
if (window.mermaid) {
169+
window.mermaid.initialize({ startOnLoad: false, securityLevel: 'strict' });
170+
window.mermaid.run().catch((e) => console.error('[mermaid] render failed', e));
171+
} else {
172+
console.error('[mermaid] global mermaid not found');
173+
}
174+
}
175+
176+
document.addEventListener('astro:page-load', renderMermaid);
177+
renderMermaid();
178+
</script>
132179
</div>
133180
</main>
134181
<Footer />

src/pages/[slug].astro

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ import TextDetailLayout from "@layouts/TextDetailLayout.astro";
33
import { getCollectionInDefaultLocale } from "@pages/_utils";
44
import { removeLocalePrefix } from "@i18n/utils";
55
6+
// Generate all static paths for tutorial pages
67
export const getStaticPaths = async () => {
78
const pages = await getCollectionInDefaultLocale("text-detail");
9+
810
return pages
911
.map((page) => {
1012
const slug = removeLocalePrefix(page.slug);
1113
12-
// if slug has / at the beginning (and will if we only remove
13-
// the locale prefix) then chop it off
14-
// this is necessary because this file is [slug].astro and
15-
// not [...slug].astro, so sub routes are not allowed
14+
// Fix leading slash for simple slugs
1615
if (slug.startsWith("/")) {
1716
return {
1817
params: { slug: slug.slice(1) },
@@ -29,3 +28,4 @@ const { page } = Astro.props;
2928
---
3029

3130
<TextDetailLayout page={page} />
31+

tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"src/scripts/parsers/out"
1010
],
1111
"compilerOptions": {
12+
"types": ["astro/client"],
1213
"jsx": "react-jsx",
1314
"jsxImportSource": "preact",
1415
"allowJs": true,
@@ -26,5 +27,6 @@
2627
"@i18n/*": ["src/i18n/*"],
2728
"@styles/*": ["./styles/*"],
2829
}
29-
}
30+
},
31+
"include": ["src"]
3032
}

0 commit comments

Comments
 (0)