-
Notifications
You must be signed in to change notification settings - Fork 218
Linking to external types - docgen #549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
41b0e40
2fda3c3
3b3c135
cab295e
fde1a16
492e421
97e42b0
852e839
4dbff96
8b429c9
875939e
56001d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,10 @@ const contentPath = path.resolve(`${__dirname}/content-sources`); | |
| const tempHomePath = path.resolve(`${contentPath}/HOME_TEMP.md`); | ||
| const devsitePath = `/docs/reference/functions/`; | ||
|
|
||
| const { JSDOM } = require("jsdom"); | ||
|
|
||
| const typeMap = require('./type-aliases.json'); | ||
|
|
||
| /** | ||
| * Strips path prefix and returns only filename. | ||
| * @param {string} path | ||
|
|
@@ -103,6 +107,7 @@ function renameFiles() { | |
| */ | ||
| function fixLinks(file) { | ||
| return fs.readFile(file, 'utf8').then(data => { | ||
| data = addTypeAliasLinks(data); | ||
| const flattenedLinks = data | ||
| .replace(/\.\.\//g, '') | ||
| .replace(/(modules|interfaces|classes)\//g, '') | ||
|
|
@@ -116,6 +121,35 @@ function fixLinks(file) { | |
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Adds links to external documentation for type aliases that | ||
| * reference an external library. | ||
| * | ||
| * @param data File data to add external library links to. | ||
| */ | ||
| function addTypeAliasLinks(data) { | ||
| const htmlDom = new JSDOM(data); | ||
| /** | ||
| * Select .tsd-signature-type because all potential external | ||
| * links will have this identifier. | ||
| */ | ||
| const fileTags = htmlDom.window.document.querySelectorAll(".tsd-signature-type"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not immediately clear why we're selecting
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would add a comment here explaining why this tag, so that the next contributor knows the context.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding what I think Erik was doing -- just picking an ID to iterate through that would always be associated with potential external types in TypeDoc. |
||
| fileTags.forEach(tag => { | ||
| const mapping = typeMap[tag.textContent]; | ||
| if (mapping) { | ||
| console.log('Adding link to '+tag.textContent+" documentation."); | ||
egilmorez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Add the corresponding document link to this type | ||
| const linkChild = htmlDom.window.document.createElement('a'); | ||
| linkChild.setAttribute('href', mapping); | ||
| linkChild.textContent = tag.textContent; | ||
| tag.textContent = null; | ||
| tag.appendChild(linkChild); | ||
| } | ||
| }); | ||
| return htmlDom.serialize(); | ||
| } | ||
|
|
||
| let tocText = ''; | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
egilmorez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "firebase.firestore.DocumentSnapshot": "https://googleapis.dev/nodejs/firestore/latest/DocumentSnapshot.html", | ||
| "firebase.auth.UserRecord": "https://firebase.google.com/docs/reference/admin/node/admin.auth.UserRecord.html", | ||
| "firebase.auth.UserInfo": "https://firebase.google.com/docs/reference/admin/node/admin.auth.UserInfo.html" | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.