add autogenerated api doc to bottom of tutorial

This commit is contained in:
Felix Roos
2022-05-20 21:56:55 +02:00
parent b50daed0d0
commit f2a70396d1
6 changed files with 1477 additions and 215 deletions
+45
View File
@@ -0,0 +1,45 @@
import React, { Fragment } from 'react';
import { docs } from '../doc.json';
import { MiniRepl } from './MiniRepl';
function ApiDoc() {
console.log('docJson', docs);
return (
<div>
{docs
.filter((item) => !item.name?.startsWith('_') && item.kind !== 'package')
.map((item, i) => (
<Fragment key={i}>
{' '}
<h2 id={`${item.memberof ? `${item.memberof}-` : ''}${item.name}`}>
{item.memberof && item.memberof !== item.name ? `${item.memberof}.` : ''}
{item.name}
</h2>
<div
dangerouslySetInnerHTML={{
__html: item.description.replaceAll(/\{\@link ([a-zA-Z]+)?\#?([a-zA-Z]*)\}/g, (_, a, b) => {
// console.log(_, 'a', a, 'b', b);
return `<a href="#${a}${b ? `-${b}` : ''}">${a}${b ? `#${b}` : ''}</a>`;
}),
}}
/>
<ul>
{item.params?.map((param, i) => (
<li key={i}>
{param.name} ({param.type?.names?.join('|')}): {param.description?.replace(/(<([^>]+)>)/gi, '')}
</li>
))}
</ul>
{item.examples?.length && <h3>Examples</h3>}
<div className="space-y-2">
{item.examples?.map((example, k) => (
<MiniRepl key={k} tune={example} />
))}
</div>
</Fragment>
))}
</div>
);
}
export default ApiDoc;
+11
View File
@@ -693,3 +693,14 @@ If you want to contribute in another way, either
- [fork strudel repo on GitHub](https://github.com/tidalcycles/strudel)
- [Join the Discord Channel](https://discord.gg/remJ6gQA)
- [play with the Strudel REPL](https://strudel.tidalcycles.org/)
import ApiDoc from './ApiDoc';
<br />
<br />
# API Docs
The following Chapter is the technical API documentation. It is autogenerated from the jsdoc comments in the source files.
<ApiDoc />