mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-03-04 02:02:39 -05:00
* #2606 add prettier plugin sort imprts * #2606 update pnpm-lock.yaml * #2606 update eslint rules * #2606 fixes website directory formatting Co-authored-by: Ayush Sharma <ayush.sharma@trivago.com>
50 lines
1.6 KiB
TypeScript
50 lines
1.6 KiB
TypeScript
import buildDebug from 'debug';
|
|
|
|
import { TemplateUIOptions } from '@verdaccio/types';
|
|
|
|
import { Manifest, getManifestValue } from './utils/manifest';
|
|
|
|
const debug = buildDebug('verdaccio:web:render:template');
|
|
|
|
export type Template = {
|
|
manifest: Manifest;
|
|
options: TemplateUIOptions;
|
|
metaScripts?: string[];
|
|
scriptsBodyAfter?: string[];
|
|
scriptsbodyBefore?: string[];
|
|
};
|
|
|
|
// the outcome of the Webpack Manifest Plugin
|
|
export interface WebpackManifest {
|
|
[key: string]: string;
|
|
}
|
|
|
|
export default function renderTemplate(template: Template, manifest: WebpackManifest) {
|
|
debug('template %o', template);
|
|
debug('manifest %o', manifest);
|
|
|
|
return `
|
|
<!DOCTYPE html>
|
|
<html lang="en-us">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<base href="${template?.options.base}">
|
|
<title>${template?.options?.title ?? ''}</title>
|
|
<link rel="icon" href="${template?.options.base}-/static/favicon.ico"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<script>
|
|
window.__VERDACCIO_BASENAME_UI_OPTIONS=${JSON.stringify(template.options)}
|
|
</script>
|
|
${template?.metaScripts ? template.metaScripts.join('') : ''}
|
|
</head>
|
|
<body class="body">
|
|
${template?.scriptsbodyBefore ? template.scriptsbodyBefore.join('') : ''}
|
|
<div id="root"></div>
|
|
${getManifestValue(template.manifest.js, manifest, template?.options.base)
|
|
.map((item) => `<script defer="defer" src="${item}"></script>`)
|
|
.join('')}
|
|
${template?.scriptsBodyAfter ? template.scriptsBodyAfter.join('') : ''}
|
|
</body>
|
|
</html>
|
|
`;
|
|
}
|