Merge pull request 'Add Reference page to docs' (#2197) from Orasund/strudel:add-reference-page-to-docs into main

Reviewed-on: https://codeberg.org/uzu/strudel/pulls/2197
This commit is contained in:
Alex McLean
2026-11-24 12:39:31 +01:00
4 changed files with 68 additions and 33 deletions
+1
View File
@@ -118,6 +118,7 @@ export const SIDEBAR: Sidebar = {
{ text: 'Sounds', link: 'technical-manual/sounds' },
{ text: 'Docs', link: 'technical-manual/docs' },
{ text: 'Testing', link: 'technical-manual/testing' },
{ text: 'Reference', link: 'reference' },
// { text: 'Internals', link: 'technical-manual/internals' },
],
},
+36
View File
@@ -0,0 +1,36 @@
/**
* compute the list of all function with jsDoc documentation
*
* returns the list of functions in the same structure as the jsdoc json
*/
export const computeAvailableFunctions = (jsdocJson) => {
const seen = new Set(); // avoid repetition
const functions = [];
for (const doc of jsdocJson.docs) {
if (!isValid(doc)) continue;
if (seen.has(doc.name)) continue;
// jsdoc also uses "tags" for when you use @something in the comments and it doesn't know what
// @something is. We only want data from comments like `@tags superdough` here.
// If nothing is specified, we default to "untagged" for debugging
doc.tags = doc.tags?.filter((t) => t && typeof t === 'string') || ['untagged'];
const synonyms = doc.synonyms || [];
let names = [doc.name];
seen.add(doc.name);
for (const s of synonyms) {
if (!s || seen.has(s)) continue;
names.push(s);
seen.add(s);
}
doc.allNames = names.join(' ');
doc.synonyms = names.slice(1);
functions.push(doc);
}
return functions.sort((a, b) => /* a.meta.filename.localeCompare(b.meta.filename) + */ a.name.localeCompare(b.name));
};
const isValid = ({ name, description, tags = [] }) => {
const isSuperdirtOnly = tags.includes('superdirt') && !tags.includes('superdough');
return name && !name.startsWith('_') && !!description && !isSuperdirtOnly;
};
+27
View File
@@ -0,0 +1,27 @@
---
import MainLayout from '../layouts/MainLayout.astro';
import jsdocJson from '../../../doc.json';
import { computeAvailableFunctions } from '../jsDocsUtils.mjs';
import { JsDoc } from '@src/docs/JsDoc.jsx';
const functions = computeAvailableFunctions(jsdocJson);
const frontmatter = { title: 'Reference', description: '', layout: '' };
const headings = functions.map((entry) => ({
depth: 1,
slug: entry.longname,
text: entry.name,
}));
---
<MainLayout frontmatter={frontmatter} headings={headings}>
<h1>Reference</h1>
<p>
This is the long list of functions you can use. Remember that you don't need to remember all of those and that you
can already make music with a small set of functions!
</p>
{functions.map((entry) => (
<Fragment>
<h2 id={entry.longname}>{entry.name}</h2>
<JsDoc name={entry.longname} h={0} />
</Fragment>
))}
</MainLayout>
@@ -4,38 +4,9 @@ import jsdocJson from '../../../../../doc.json';
import { Textbox } from '@src/repl/components/panel/SettingsTab';
import { settingsMap, useSettings } from '@src/settings.mjs';
import { JsDoc } from '@src/docs/JsDoc';
import { computeAvailableFunctions } from '@src/jsDocsUtils.mjs';
const isValid = ({ name, description, tags = [] }) => {
const isSuperdirtOnly = tags.includes('superdirt') && !tags.includes('superdough');
return name && !name.startsWith('_') && !!description && !isSuperdirtOnly;
};
const availableFunctions = (() => {
const seen = new Set(); // avoid repetition
const functions = [];
for (const doc of jsdocJson.docs) {
if (!isValid(doc)) continue;
if (seen.has(doc.name)) continue;
// jsdoc also uses "tags" for when you use @something in the comments and it doesn't know what
// @something is. We only want data from comments like `@tags superdough` here.
// If nothing is specified, we default to "untagged" for debugging
doc.tags = doc.tags?.filter((t) => t && typeof t === 'string') || ['untagged'];
const synonyms = doc.synonyms || [];
let names = [doc.name];
seen.add(doc.name);
for (const s of synonyms) {
if (!s || seen.has(s)) continue;
names.push(s);
seen.add(s);
}
doc.allNames = names.join(' ');
doc.synonyms = names.slice(1);
functions.push(doc);
}
return functions.sort((a, b) => /* a.meta.filename.localeCompare(b.meta.filename) + */ a.name.localeCompare(b.name));
})();
const availableFunctions = computeAvailableFunctions(jsdocJson);
const tagCounts = {};
const ignoredTags = ['superdirt'];
@@ -173,7 +144,7 @@ export const Reference = memo(function Reference() {
id="reference-container"
>
<div className="prose dark:prose-invert min-w-full px-1 text-sm">
<h2>API Reference</h2>
<h2>Reference</h2>
<p className="font-sans text-md">
This is the long list of functions you can use. Remember that you don't need to remember all of those and
that you can already make music with a small set of functions!
@@ -200,7 +171,7 @@ export const Reference = memo(function Reference() {
<section key={i} className="font-sans">
<div className="flex flex-row items-center mt-8 justify-between">
<h3 className="font-mono my-0 pt-4" id={`doc-${entry.name}`}>
{entry.name}
<a href={`/reference#${entry.longname}`}>{entry.name}</a>
</h3>
{entry.tags && (
<span className="ml-2 text-xs text-foreground border border-muted px-1 py-0.5">