vike
Version:
The Framework *You* Control - Next.js & Nuxt alternative for unprecedented flexibility and dependability.
30 lines (29 loc) • 1.66 kB
JavaScript
export { injectAssets__public };
import { assertUsage, assertWarning, castProp, hasProp } from '../../utils.js';
import { injectHtmlTagsToString } from '../injectAssets.js';
// TODO/v1-release: remove
async function injectAssets__public(htmlString, pageContext) {
assertWarning(false, '`_injectAssets()` is deprecated and will be removed.', { onlyOnce: true, showStackTrace: true });
assertUsage(typeof htmlString === 'string', '[injectAssets(htmlString, pageContext)]: Argument `htmlString` should be a string.', { showStackTrace: true });
assertUsage(pageContext, '[injectAssets(htmlString, pageContext)]: Argument `pageContext` is missing.', {
showStackTrace: true,
});
const errMsg = (body) => '[injectAssets(htmlString, pageContext)]: ' +
body +
'. Make sure that `pageContext` is the object that Vike provided to your `render(pageContext)` hook.';
assertUsage(hasProp(pageContext, 'urlPathname', 'string'), errMsg('`pageContext.urlPathname` should be a string'), {
showStackTrace: true,
});
assertUsage(hasProp(pageContext, 'pageId', 'string'), errMsg('`pageContext.pageId` should be a string'), {
showStackTrace: true,
});
assertUsage(hasProp(pageContext, '__getPageAssets'), errMsg('`pageContext.__getPageAssets` is missing'), {
showStackTrace: true,
});
assertUsage(hasProp(pageContext, '_passToClient', 'string[]'), errMsg('`pageContext._passToClient` is missing'), {
showStackTrace: true,
});
castProp(pageContext, '__getPageAssets');
htmlString = await injectHtmlTagsToString([htmlString], pageContext, null);
return htmlString;
}