Skip to content

Commit 9910aa2

Browse files
committed
Add source links
1 parent 4958a31 commit 9910aa2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

docs/generate.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type Method = {
2727
type DocumentedFunction = Method & {
2828
type: 'function'
2929
path: string
30+
source: string | undefined
3031
aliases: string[] | undefined
3132
example: string | undefined
3233
}
@@ -35,6 +36,7 @@ type DocumentedFunction = Method & {
3536
type DocumentedClass = {
3637
type: 'class'
3738
path: string
39+
source: string | undefined
3840
name: string
3941
aliases: string[] | undefined
4042
description: string
@@ -114,7 +116,7 @@ async function main() {
114116
await writeMarkdownFiles(documentedAPIs)
115117
}
116118

117-
//#region TypeDoc Loading
119+
//#region TypeDoc
118120

119121
// Load the TypeDoc JSON representation, either from a JSON file or by running
120122
// TypeDoc against the project
@@ -322,6 +324,7 @@ function getDocumentedFunction(
322324
return {
323325
type: 'function',
324326
path: getDocumentedApiPath(fullName),
327+
source: node.sources?.[0]?.url,
325328
aliases: getDocumentedApiAliases(node.comment!),
326329
example: node.comment?.getTag('@example')?.content
327330
? processComment(node.comment.getTag('@example')!.content)
@@ -376,6 +379,7 @@ function getDocumentedClass(
376379
aliases: getDocumentedApiAliases(node.comment!),
377380
example: undefined,
378381
path: getDocumentedApiPath(fullName),
382+
source: node.sources?.[0]?.url,
379383
name: getApiNameFromFullName(fullName),
380384
description: getDocumentedApiDescription(node.comment!),
381385
constructor,
@@ -573,6 +577,7 @@ const h2 = (heading: string, body: string) => h(2, heading, body)
573577
const h3 = (heading: string, body: string) => h(3, heading, body)
574578
const h4 = (heading: string, body: string) => h(4, heading, body)
575579
const code = (content: string) => `\`${content}\``
580+
const p = (content: string) => `${content}`
576581
const pre = async (content: string, lang = 'ts') => {
577582
try {
578583
content = await prettier.format(content, { parser: 'typescript' })
@@ -649,6 +654,7 @@ function getCommonMarkdown(comment: DocumentedFunction | DocumentedClass): (stri
649654
return [
650655
`---\ntitle: ${comment.name}\n---`,
651656
h1(comment.name),
657+
comment.source ? p(`[View Source](${comment.source})`) : undefined,
652658
h2('Summary', comment.description),
653659
comment.aliases ? h2('Aliases', comment.aliases.join(', ')) : undefined,
654660
].filter(Boolean)

0 commit comments

Comments
 (0)