feat(website): Add utility for resolving summaries for json items (#8734)

This commit is contained in:
Suneet Tipirneni
2022-10-11 10:01:32 -04:00
committed by GitHub
parent 9d8179c6a7
commit b05be9ec08

View File

@@ -0,0 +1,47 @@
import type {
ApiItemJSON,
DocNodeJSON,
DocCodeSpanJSON,
DocPlainTextJSON,
DocNodeContainerJSON,
} from '@discordjs/api-extractor-utils';
export function tryResolveDescription(member: ApiItemJSON) {
const { summary } = member!;
if (!summary) {
return undefined;
}
let retVal = '';
function recurseNodes(node: DocNodeJSON) {
switch (node.kind) {
case 'CodeSpan':
retVal += (node as DocCodeSpanJSON).code;
break;
case 'PlainText':
retVal += (node as DocPlainTextJSON).text;
break;
case 'Section':
case 'Paragraph':
for (const currentNode of (node as DocNodeContainerJSON).nodes) {
recurseNodes(currentNode);
}
break;
default:
break;
}
}
for (const node of summary.nodes) {
recurseNodes(node);
}
if (retVal === '') {
return null;
}
return retVal;
}