From ea821cc961f3e76be73bc17f3afbf370e0d51214 Mon Sep 17 00:00:00 2001 From: almostSouji Date: Sun, 10 Nov 2024 15:39:11 +0100 Subject: [PATCH] fix(docs): handle missing sources fixes #227 --- src/functions/docs.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/functions/docs.ts b/src/functions/docs.ts index eafd361..50aa71c 100644 --- a/src/functions/docs.ts +++ b/src/functions/docs.ts @@ -235,7 +235,7 @@ function formatExample(blocks?: any[]) { function formatItem(_item: any, _package: string, version: string, member?: string) { const itemLink = docsLink(_item, _package, version, member); const item = effectiveItem(_item, member); - const sourceUrl = `${item.sourceURL}#L${item.sourceLine}`; + const sourceUrl = item.sourceURL ? `${item.sourceURL}${item.sourceLine ? `#L${item.sourceLine}` : ''}` : null; const [emojiId, emojiName] = itemKindEmoji(item.kind, version === 'main'); @@ -252,7 +252,8 @@ function formatItem(_item: any, _package: string, version: string, member?: stri parts.push(underline(bold(hyperlink(item.displayName, itemLink)))); const head = `<:${emojiName}:${emojiId}>`; - const tail = ` ${hyperlink(inlineCode(`@${version}`), sourceUrl, 'source code')}`; + const versionString = inlineCode(`@${version}`); + const tail = sourceUrl ? ` ${hyperlink(versionString, sourceUrl, 'source code')}` : versionString; const middlePart = item.isDeprecated ? strikethrough(parts.join(' ')) : parts.join(' '); const lines: string[] = [[head, middlePart, tail].join(' ')];