Skip to content

Commit 53b88c1

Browse files
committed
Update reference to show p5.sound
1 parent 8b04e14 commit 53b88c1

File tree

9 files changed

+38
-17
lines changed

9 files changed

+38
-17
lines changed

src/components/CodeEmbed/frame.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ interface CodeBundle {
66
htmlBody?: string;
77
js?: string;
88
base?: string;
9+
scripts?: string[];
910
}
1011

1112
/*
@@ -41,6 +42,7 @@ canvas {
4142
}
4243
${code.css || ""}
4344
</style>
45+
${(code.scripts || []).map((src) => `<script type="text/javascript" src="${src}"></script>`).join('\n')}
4446
<body>${code.htmlBody || ""}</body>
4547
<script id="code" type="text/javascript">${wrapSketch(code.js) || ""}</script>
4648
<script type="text/javascript">
@@ -67,6 +69,7 @@ export interface CodeFrameProps {
6769
width?: number | string;
6870
base?: string;
6971
lazyLoad?: boolean;
72+
scripts?: string[];
7073
}
7174

7275
/*
@@ -155,6 +158,7 @@ export const CodeFrame = (props: CodeFrameProps) => {
155158
css: props.cssCode,
156159
htmlBody: props.htmlBodyCode,
157160
base: props.base,
161+
scripts: props.scripts,
158162
})}
159163
sandbox="allow-scripts allow-popups allow-modals allow-forms allow-same-origin"
160164
aria-label="Code Preview"

src/components/CodeEmbed/index.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useState, useEffect, useRef } from "preact/hooks";
22
import CodeMirror, { EditorView } from "@uiw/react-codemirror";
33
import { javascript } from "@codemirror/lang-javascript";
4-
import { cdnLibraryUrl } from "@/src/globals/globals";
4+
import { cdnLibraryUrl, cdnSoundUrl } from "@/src/globals/globals";
55

66
import { CodeFrame } from "./frame";
77
import { CopyCodeButton } from "../CopyCodeButton";
@@ -21,6 +21,7 @@ import { Icon } from "../Icon";
2121
* TODO: refactor this prop behavior
2222
* allowSideBySide?: boolean
2323
* fullWidth?: boolean
24+
* includeSound?: boolean
2425
* }
2526
*/
2627
export const CodeEmbed = (props) => {
@@ -90,6 +91,7 @@ export const CodeEmbed = (props) => {
9091
base={props.base}
9192
frameRef={codeFrameRef}
9293
lazyLoad={props.lazyLoad}
94+
scripts={props.includeSound ? [cdnSoundUrl] : []}
9395
/>
9496
</div>
9597
<div className={`flex gap-2.5 ${largeSketch ? "flex-row" : "md:flex-row lg:flex-col"}`}>

src/components/ReferenceDirectoryWithFilter/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,11 @@ export const ReferenceDirectoryWithFilter = ({
116116
subcat: { name: string },
117117
category: { name: string },
118118
) => {
119-
return !(!subcat.name || !category.name || subcat.name === "p5.sound");
119+
return !(!subcat.name || !category.name);
120120
}
121121

122122
const getSubcatHeading = (
123-
subcat: { name: string },
123+
subcat: { name: string; entry?: any },
124124
category: { name: string },
125125
) => {
126126
if (!subcatShouldHaveHeading(subcat, category)) {
@@ -129,10 +129,10 @@ export const ReferenceDirectoryWithFilter = ({
129129

130130
return (
131131
<>
132-
{subcat.name.includes("p5.") ? (
132+
{subcat.entry ? (
133133
<a
134134
id={subcat.name}
135-
href={`/reference/${category.name === "p5.sound" ? "p5.sound" : "p5"}/${subcat.name}`}
135+
href={`/reference/${category.name === "p5.sound" ? "p5.sound" : "p5"}/${subcat.name}/`}
136136
>
137137
<h3 className="m-0 py-gutter-md">{subcat.name}</h3>
138138
</a>

src/content/reference/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const categories = [
2121
"Structure", // TODO: move to top once revised
2222
"Constants",
2323
"Foundation",
24+
"p5.sound",
2425
] as const;
2526

2627
const paramSchema = z.object({
@@ -32,7 +33,7 @@ const paramSchema = z.object({
3233

3334
const returnSchema = z.object({
3435
description: z.string(),
35-
type: z.string(),
36+
type: z.string().optional(),
3637
});
3738

3839
const exampleSchema = z.string();

src/globals/globals.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ export const libraryDownloadUrl =
2121
`https://github.com/processing/p5.js/releases/download/v${p5Version}/p5.js` as const;
2222
export const minifiedLibraryDownloadUrl =
2323
`https://github.com/processing/p5.js/releases/download/v${p5Version}/p5.min.js` as const;
24+
export const cdnSoundUrl =
25+
`https://cdn.jsdelivr.net/npm/p5@${p5Version}/lib/addons/p5.sound.js` as const;

src/layouts/ReferenceItemLayout.astro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ const seenParams: Record<string, true> = {};
118118
editable
119119
lazyLoad={false}
120120
allowSideBySide={true}
121+
includeSound={entry.data.module === 'p5.sound'}
121122
/>
122123
);
123124
})}

src/layouts/ReferenceLayout.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const categoryData = categories.map((category) => {
5151
...new Set(
5252
directEntries
5353
// Ignore classes here, they will be added later
54-
.filter((e) => e.data.submodule && !e.data.isConstructor)
54+
.filter((e) => e.data.submodule && !e.data.isConstructor && (!e.data.class || e.data.class === 'p5'))
5555
.map((e) => e.data.submodule)
5656
).values(),
5757
].sort();

src/scripts/parsers/reference.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,20 @@ export const parseLibraryReference =
1919
async (): Promise<ParsedLibraryReference | null> => {
2020
// Clone p5.js
2121
await cloneLibraryRepo(localPath);
22-
await saveYuidocOutput('p5.js', 'data-p5');
22+
// TODO(dave): let this happen via `npm run docs` in the p5 repo once we
23+
// merge the 2.0 branch
24+
await saveYuidocOutput('p5.js', 'data-p5', {
25+
flags: `--config ${path.join(__dirname, '../../../yuidoc.json')}`,
26+
inputPath: './src',
27+
});
2328
const p5Data = await getYuidocOutput('data-p5');
2429
if (!p5Data) throw new Error('Error generating p5 reference data!');
2530

2631
// Clone p5.sound.js
2732
await cloneLibraryRepo(
2833
localSoundPath,
29-
'https://github.com/processing/p5.sound.js.git',
30-
'moduleref', // 'main',
34+
'https://github.com/davepagurek/p5.sound.js-pre-release.git', // 'https://github.com/processing/p5.sound.js.git',
35+
'moduleref-doc-comments', // 'main',
3136
{ shouldFixAbsolutePathInPreprocessor: false }
3237
);
3338
await saveYuidocOutput('p5.sound.js', 'data-sound');
@@ -76,15 +81,25 @@ const getYuidocOutput = async (outDirName: string): Promise<ParsedLibraryReferen
7681
/**
7782
* Parses the p5.js library using YUIDoc and captures the output
7883
*/
79-
export const saveYuidocOutput = async (inDirName: string, outDirName: string) => {
84+
export const saveYuidocOutput = async (
85+
inDirName: string,
86+
outDirName: string,
87+
{
88+
flags = '',
89+
inputPath = '.',
90+
}: {
91+
flags?: string
92+
inputPath?: string
93+
} = {}
94+
) => {
8095
console.log("Running YUIDoc command and capturing output...");
8196
const outputFilePath = path.join(yuidocOutputPath, outDirName);
8297
try {
8398
await fs.mkdir(yuidocOutputPath, { recursive: true });
8499
const inPath = path.join(__dirname, "in", inDirName);
85100
console.log(inPath)
86101
await new Promise((resolve, reject) => {
87-
exec(`yuidoc -p --outdir ${outputFilePath} .`, { cwd: inPath }, (error, stdout) => {
102+
exec(`yuidoc -p --outdir ${outputFilePath} ${flags} ${inputPath}`, { cwd: inPath }, (error, stdout) => {
88103
if (error) {
89104
console.error(`Error running YUIDoc command: ${error}`);
90105
reject(error);

yuidoc.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
"description": "",
44
"url": "",
55
"options": {
6-
"preprocessor": "./src/scripts/parsers/in/p5.js/docs/preprocessor.js",
7-
"paths": [
8-
"./src/scripts/parsers/in/p5.js/src/",
9-
"./src/scripts/parsers/in/p5.js/lib/addons/"
10-
]
6+
"preprocessor": "./docs/preprocessor.js"
117
}
128
}

0 commit comments

Comments
 (0)