-
Notifications
You must be signed in to change notification settings - Fork 38
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
Add favicon to TypeDoc generated output via plugin script #132
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { copyFileSync } from 'fs'; | ||
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. It's been a minute since I've had to deal with commonjs vs. modules vs. ts config stuff. I'm not sure if an |
||
import { join } from 'path'; | ||
|
||
/** | ||
* This script is passed into typedoc at build time, and is used to hook into their rendering | ||
* pipeline allowing us to modify the output. | ||
* | ||
* example: typedoc --plugin ./assets/docs-theme.mjs | ||
* TypeDoc documentation: https://github.com/TypeStrong/typedoc/blob/master/internal-docs/custom-themes.md#hooks-v0228 | ||
*/ | ||
|
||
export const load = (app) => { | ||
// See PageEvent: https://github.com/TypeStrong/typedoc/blob/f2d2abe054feca91b89c00c33e1d726bbda85dcb/src/lib/output/events.ts#L134 | ||
app.renderer.on('endPage', onPageRendered.bind(this)); | ||
// See RendererEvent: https://github.com/TypeStrong/typedoc/blob/f2d2abe054feca91b89c00c33e1d726bbda85dcb/src/lib/output/events.ts#L47 | ||
app.renderer.once('endRender', onRenderFinished.bind(this)); | ||
}; | ||
|
||
function onPageRendered(page) { | ||
// after the page is rendered we want to insert a favicon into head | ||
if (page && page.contents) { | ||
page.contents = page.contents.replace( | ||
'</head>', | ||
'<link rel="icon" href="./favicon-32x32.png"/></head>' | ||
); | ||
} | ||
} | ||
|
||
function onRenderFinished() { | ||
// rendering complete, copy favicon asset into /docs folder | ||
if (process) { | ||
const workingDir = process.cwd(); | ||
const startingFavIcon = join(workingDir, '/assets/favicon-32x32.png'); | ||
const endingFavIcon = join(workingDir, './docs', '/favicon-32x32.png'); | ||
|
||
copyFileSync(startingFavIcon, endingFavIcon); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I needed to add
node
here to get lint to stop whining aboutprocess
not being accessible indocs-theme.mjs
. Honestly I'm not sure if we needbrowser
here at all.