Skip to content

Commit

Permalink
Merge branch 'main' into marc/update-to-scalar-1.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SaltyAom authored Jan 24, 2024
2 parents 702bf43 + d8e7294 commit 0e3e344
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
52 changes: 24 additions & 28 deletions src/scalar/index.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
import scalarElysiaTheme from './theme'
import type { ReferenceConfiguration } from './types'

export const ScalarRender = (version: string, config: ReferenceConfiguration, scalarCDN: string) => {
const overrideScalarCDN = scalarCDN ? scalarCDN : `https://cdn.jsdelivr.net/npm/@scalar/api-reference@${version}/dist/browser/standalone.min.js`

return `<!doctype html>
<html>
<head>
<title>API Reference</title>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1" />
<style>
body {
margin: 0;
}
</style>
<style>
${config.customCss ?? scalarElysiaTheme}
</style>
</head>
<body>
<script
id="api-reference"
data-url="${config.spec?.url}"></script>
<script src="${overrideScalarCDN}"></script>
</body>
</html>`
}
export const ScalarRender = (version: string, config: ReferenceConfiguration, cdn: string) => `<!doctype html>
<html>
<head>
<title>API Reference</title>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1" />
<style>
body {
margin: 0;
}
</style>
<style>
${config.customCss ?? scalarElysiaTheme}
</style>
</head>
<body>
<script
id="api-reference"
data-configuration="JSON.stringify(${Bun.inspect(config)})"></script>
<script src="${cdn ? cdn:`https://cdn.jsdelivr.net/npm/@scalar/api-reference@${version}/dist/browser/standalone.min.js`}"></script>
</body>
</html>`
6 changes: 6 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ export interface ElysiaSwaggerConfig<Path extends string = '/swagger'> {
/**
* Optional override to specifying the path for the Scalar bundle
*
* Custom URL or path to locally hosted Scalar bundle
*
* Lease blank to use default jsdeliver.net CDN
*
* @default ''
* @example 'https://unpkg.com/@scalar/[email protected]/dist/browser/standalone.js'
* @example '/public/standalone.js'
* @see https://github.com/scalar/scalar
*/
scalarCDN?: string
Expand Down

0 comments on commit 0e3e344

Please sign in to comment.