From 13b1c0b254ddfacad1eac7eb94a3ac2a761450b3 Mon Sep 17 00:00:00 2001 From: David Mosberger-Tang Date: Thu, 19 Dec 2024 11:13:18 -0700 Subject: [PATCH] feat: add redocBundleURL option It is helpful to be able render documentation with a non-standard redoc bundle, e.g., for testing. In theory, one could use a custom HTML template for this purpose but in practice that's not straight-forward because the template would have to be different depending on whether or not `preview-docs` or `build-docs` is run. The template would also have to include all the CSS code. --- .changeset/heavy-gifts-beg.md | 5 +++++ packages/cli/src/commands/build-docs/utils.ts | 9 ++++++--- .../preview-server/preview-server.ts | 16 ++++++++++------ 3 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 .changeset/heavy-gifts-beg.md diff --git a/.changeset/heavy-gifts-beg.md b/.changeset/heavy-gifts-beg.md new file mode 100644 index 0000000000..31a24dc939 --- /dev/null +++ b/.changeset/heavy-gifts-beg.md @@ -0,0 +1,5 @@ +--- +"@redocly/cli": minor +--- + +add redocBundleURL option diff --git a/packages/cli/src/commands/build-docs/utils.ts b/packages/cli/src/commands/build-docs/utils.ts index 64976fa9a7..4fdc28508b 100644 --- a/packages/cli/src/commands/build-docs/utils.ts +++ b/packages/cli/src/commands/build-docs/utils.ts @@ -75,6 +75,11 @@ export async function getPageHTML( : redocOptions?.htmlTemplate ? resolve(configPath ? dirname(configPath) : '', redocOptions.htmlTemplate) : join(__dirname, './template.hbs'); + + const redocBundleURL = + redocOptions.redocBundleURL || + 'https://cdn.redocly.com/redoc/v${redocCurrentVersion}/bundles/redoc.standalone.js'; + const template = compile(readFileSync(templateFileName).toString()); return template({ redocHTML: ` @@ -86,9 +91,7 @@ export async function getPageHTML( Redoc.${'hydrate(__redoc_state, container)'}; `, - redocHead: - `` + - css, + redocHead: `` + css, title: title || api.info.title || 'ReDoc documentation', disableGoogleFont, templateOptions, diff --git a/packages/cli/src/commands/preview-docs/preview-server/preview-server.ts b/packages/cli/src/commands/preview-docs/preview-server/preview-server.ts index 24865d80ab..d3fef9f628 100644 --- a/packages/cli/src/commands/preview-docs/preview-server/preview-server.ts +++ b/packages/cli/src/commands/preview-docs/preview-server/preview-server.ts @@ -10,7 +10,9 @@ import type { IncomingMessage } from 'http'; function getPageHTML( htmlTemplate: string, - redocOptions: object = {}, + redocOptions: { + redocBundleURL?: string; + } = {}, useRedocPro: boolean, wsPort: number, host: string @@ -24,6 +26,12 @@ function getPageHTML( const template = compile(templateSrc); + const redocBundleURL = + redocOptions.redocBundleURL || + (useRedocPro + ? 'https://cdn.redocly.com/reference-docs/latest/redocly-reference-docs.min.js' + : 'https://cdn.redocly.com/redoc/latest/bundles/redoc.standalone.js'); + return template({ redocHead: ` - + `, redocHTML: `