'use strict'; const assert = require('assert'); const { getSerializableSpans } = require('../tracing/tracing-middleware'); const sanitizeHtml = require('../lib/sanitize-html'); const safeJson = require('../lib/safe-json'); const getDependenciesForEntryPointName = require('../lib/get-dependencies-for-entry-point-name'); const getFaviconAssetUrls = require('../lib/get-favicon-asset-urls'); const faviconMap = getFaviconAssetUrls(); async function renderPageHtml({ pageOptions, // Make sure you sanitize this before passing it to us bodyHtml, vmRenderContext, }) { assert(vmRenderContext); assert(pageOptions); assert(pageOptions.title); assert(pageOptions.entryPoint); assert(pageOptions.cspNonce); const { styles, scripts } = getDependenciesForEntryPointName(pageOptions.entryPoint); // Serialize the state for when we run the Hydrogen render again client-side to // re-hydrate the DOM const serializedMatrixPublicArchiveContext = JSON.stringify({ ...vmRenderContext, }); const serializableSpans = getSerializableSpans(); const serializedSpans = JSON.stringify(serializableSpans); // We shouldn't let some pages be indexed by search engines let maybeNoIndexHtml = ''; if (!pageOptions.shouldIndex) { maybeNoIndexHtml = ``; } const pageHtml = ` ${maybeNoIndexHtml} ${sanitizeHtml(`${pageOptions.title}`)} ${styles .map( (styleUrl) => `` ) .join('\n')} ${bodyHtml} ${ /** * This inline snippet is used in to scroll the Hydrogen timeline to the * right place immediately when the page loads instead of waiting for * Hydrogen to load, hydrate and finally scroll. */ '' } ${scripts .map( (scriptUrl) => `` ) .join('\n')} `; return pageHtml; } module.exports = renderPageHtml;