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

feat: add redocBundleURL option #1835

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .changeset/heavy-gifts-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@redocly/cli": minor
---

add redocBundleURL option
9 changes: 6 additions & 3 deletions packages/cli/src/commands/build-docs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: `
Expand All @@ -86,9 +91,7 @@ export async function getPageHTML(
Redoc.${'hydrate(__redoc_state, container)'};

</script>`,
redocHead:
`<script src="https://cdn.redocly.com/redoc/v${redocCurrentVersion}/bundles/redoc.standalone.js"></script>` +
css,
redocHead: `<script src="${redocBundleURL}"></script>` + css,
title: title || api.info.title || 'ReDoc documentation',
disableGoogleFont,
templateOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import type { IncomingMessage } from 'http';

function getPageHTML(
htmlTemplate: string,
redocOptions: object = {},
redocOptions: {
redocBundleURL?: string;
} = {},
useRedocPro: boolean,
wsPort: number,
host: string
Expand All @@ -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: `
<script>
Expand All @@ -33,11 +41,7 @@ function getPageHTML(
</script>
<script src="/simplewebsocket.min.js"></script>
<script src="/hot.js"></script>
<script src="${
useRedocPro
? 'https://cdn.redocly.com/reference-docs/latest/redocly-reference-docs.min.js'
: 'https://cdn.redocly.com/redoc/latest/bundles/redoc.standalone.js'
}"></script>
<script src="${redocBundleURL}"></script>
`,
redocHTML: `
<div id="redoc"></div>
Expand Down