diff --git a/.eslintrc.json b/.eslintrc.json index e16003fe..4a280aea 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,7 +1,8 @@ { "env": { "browser": true, - "es2021": true + "es2021": true, + "node": true }, "ignorePatterns": ["dist", "src/pinecone-generated-ts-fetch", "src/v0"], "extends": [ diff --git a/docs-styles.css b/assets/docs-styles.css similarity index 100% rename from docs-styles.css rename to assets/docs-styles.css diff --git a/assets/docs-theme.mjs b/assets/docs-theme.mjs new file mode 100644 index 00000000..d56637f8 --- /dev/null +++ b/assets/docs-theme.mjs @@ -0,0 +1,38 @@ +import { copyFileSync } from 'fs'; +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( + '', + '' + ); + } +} + +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); + } +} diff --git a/assets/favicon-32x32.png b/assets/favicon-32x32.png new file mode 100644 index 00000000..4f9c615e Binary files /dev/null and b/assets/favicon-32x32.png differ diff --git a/package.json b/package.json index 97f52d76..bb0582ee 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/typedoc.json b/typedoc.json index 6c4aa39e..4d4aa784 100644 --- a/typedoc.json +++ b/typedoc.json @@ -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"