Skip to content
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

Merged
merged 3 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"env": {
"browser": true,
"es2021": true
"es2021": true,
"node": true
Copy link
Contributor Author

@austin-denoble austin-denoble Oct 3, 2023

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 about process not being accessible in docs-theme.mjs. Honestly I'm not sure if we need browser here at all.

},
"ignorePatterns": ["dist", "src/pinecone-generated-ts-fetch", "src/v0"],
"extends": [
Expand Down
File renamed without changes.
38 changes: 38 additions & 0 deletions assets/docs-theme.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { copyFileSync } from 'fs';
Copy link
Contributor Author

@austin-denoble austin-denoble Oct 3, 2023

Choose a reason for hiding this comment

The 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 .mjs file was the best way to do this, and I also wasn't sure if there were specific considerations around adding a script that's outside /src/ and used in CI / build. Definitely open to changing things up here.

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);
}
}
Binary file added assets/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"scripts": {
"build": "rm -rf dist/ && tsc",
"version": "jq --null-input --arg version $npm_package_version '{\"name\": \"@pinecone-database/pinecone\", \"version\": $version}' > src/version.json",
"docs:build": "typedoc",
"docs:build": "typedoc --plugin ./assets/docs-theme.mjs",
"format": "prettier --write .",
"lint": "eslint src/ --ext .ts",
"repl": "npm run build && node utils/replInit.ts",
Expand Down
2 changes: 1 addition & 1 deletion typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"includeVersion": true,
"excludeInternal": true,
"out": "docs",
"customCss": "./docs-styles.css",
"customCss": "./assets/docs-styles.css",
"navigationLinks": {
"Github Repo": "https://github.com/pinecone-io/pinecone-ts-client",
"Pinecone Docs": "https://docs.pinecone.io"
Expand Down