INNER CODE UNIT · TypeScript
firstLink
ahmet/awesome-web3 · lib/catalog.ts:80
function firstLink(nodes: MdNode[]): { title: string; url: string } | null {
for (const node of nodes) {
if (node.type === 'link' && node.url) {
return { title: textOf(node).trim(), url: node.url }
}
if (node.children) {
const nested = firstLink(node.children)
if (nested) return nested
}
}
return null
}
function descriptionAfterLink(nodes: MdNode[]) {
const idx = nodes.findIndex((node) => node.type === 'link')
if (idx === -1) return ''
return textOf({ type: 'paragraph', children: nodes.slice(idx + 1) })
.replace(/^\s*[-–—:]\s*/, '')