Skip to content

Commit ea821cc

Browse files
committed
fix(docs): handle missing sources
fixes #227
1 parent 379e686 commit ea821cc

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/functions/docs.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ function formatExample(blocks?: any[]) {
235235
function formatItem(_item: any, _package: string, version: string, member?: string) {
236236
const itemLink = docsLink(_item, _package, version, member);
237237
const item = effectiveItem(_item, member);
238-
const sourceUrl = `${item.sourceURL}#L${item.sourceLine}`;
238+
const sourceUrl = item.sourceURL ? `${item.sourceURL}${item.sourceLine ? `#L${item.sourceLine}` : ''}` : null;
239239

240240
const [emojiId, emojiName] = itemKindEmoji(item.kind, version === 'main');
241241

@@ -252,7 +252,8 @@ function formatItem(_item: any, _package: string, version: string, member?: stri
252252
parts.push(underline(bold(hyperlink(item.displayName, itemLink))));
253253

254254
const head = `<:${emojiName}:${emojiId}>`;
255-
const tail = ` ${hyperlink(inlineCode(`@${version}`), sourceUrl, 'source code')}`;
255+
const versionString = inlineCode(`@${version}`);
256+
const tail = sourceUrl ? ` ${hyperlink(versionString, sourceUrl, 'source code')}` : versionString;
256257
const middlePart = item.isDeprecated ? strikethrough(parts.join(' ')) : parts.join(' ');
257258

258259
const lines: string[] = [[head, middlePart, tail].join(' ')];

0 commit comments

Comments
 (0)