diff --git a/apps/website/src/util/summary.ts b/apps/website/src/util/summary.ts new file mode 100644 index 000000000..46852655f --- /dev/null +++ b/apps/website/src/util/summary.ts @@ -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; +}