mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +01:00
feat(website): Add utility for resolving summaries for json items (#8734)
This commit is contained in:
47
apps/website/src/util/summary.ts
Normal file
47
apps/website/src/util/summary.ts
Normal 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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user