$config['domain'],
'devMode' => $config['is_dev'],
'cookieHost' => $config['cookie_host'],
]);
return <<
{$title}
{$ctx->renderMeta($meta)}
{$ctx->renderStatic($static, $theme)}
if_true($opts['full_width'], ' class="full-width"')}>
{$ctx->renderHeader($theme, renderLogo($ctx, $opts['logo_path_map'], $opts['logo_link_map']))}
{$ctx->renderScript($js, $unsafe_lang, $opts['dynlogo_enabled'])}
HTML;
}
function renderScript($ctx, $unsafe_js, $unsafe_lang, $enable_dynlogo) {
global $config;
$styles = json_encode($ctx->styleNames);
$versions = !$config['is_dev'] ? json_encode($config['static']) : '{}';
return <<
StaticManager.setStyles({$styles}, {$versions});
{$ctx->if_true($unsafe_js, '(function(){'.$unsafe_js.'})();')}
{$ctx->if_true($unsafe_lang, 'extend(__lang, '.$unsafe_lang.');')}
{$ctx->if_true($enable_dynlogo, 'DynamicLogo.init();')}
ThemeSwitcher.init();
HTML;
}
function renderMeta($ctx, $meta) {
if (empty($meta))
return '';
return implode('', array_map(function(array $item): string {
$s = ' $v)
$s .= ' '.htmlescape($k).'="'.htmlescape($v).'"';
$s .= '>';
return $s;
}, $meta));
}
function renderStatic($ctx, $static, $theme) {
global $config;
$html = [];
$dark = $theme == 'dark';
$ctx->styleNames = [];
foreach ($static as $name) {
// javascript
if (str_ends_with($name, '.js'))
$html[] = jsLink($name);
// cs
else if (str_ends_with($name, '.css')) {
$html[] = cssLink($name, 'light', $style_name);
$ctx->styleNames[] = $style_name;
if ($dark)
$html[] = cssLink($name, 'dark', $style_name);
else if (!$config['is_dev'])
$html[] = cssPrefetchLink(str_replace('.css', '_dark.css', $name));
}
}
return implode("\n", $html);
}
function jsLink(string $name): string {
return '';
}
function cssLink(string $name, string $theme, &$bname = null): string {
global $config;
$dname = dirname($name);
$bname = basename($name);
if (($pos = strrpos($bname, '.')))
$bname = substr($bname, 0, $pos);
if ($config['is_dev']) {
$href = '/sass.php?name='.urlencode($bname).'&theme='.$theme.'&v='.time();
} else {
$version = getStaticVersion('css/'.$bname.($theme == 'dark' ? '_dark' : '').'.css');
$href = $dname.'/'.$bname.($theme == 'dark' ? '_dark' : '').'.css?'.$version;
}
$id = 'style_'.$bname;
if ($theme == 'dark')
$id .= '_dark';
return '';
}
function cssPrefetchLink(string $name): string {
$url = $name.'?'.getStaticVersion($name);
return <<