From 5eecaffdef97aa938fcbc455ec02e52d08d5af29 Mon Sep 17 00:00:00 2001 From: Evgeny Zinoviev Date: Mon, 11 Jul 2022 00:14:21 +0300 Subject: skin/base: fix static version rendering --- skin/base.skin.php | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'skin/base.skin.php') diff --git a/skin/base.skin.php b/skin/base.skin.php index 2be71dc..2d71312 100644 --- a/skin/base.skin.php +++ b/skin/base.skin.php @@ -76,30 +76,29 @@ function renderStatic($ctx, $static, $theme) { $dark = $theme == 'dark'; $ctx->styleNames = []; foreach ($static as $name) { - // list($name, $options) = $item; - $version = $config['is_dev'] ? time() : $config['static'][substr($name, 1)] ?? 'notfound'; + // javascript if (str_ends_with($name, '.js')) - $html[] = jsLink($name, $version); + $html[] = jsLink($name); + + // cs else if (str_ends_with($name, '.css')) { - $html[] = cssLink($name, 'light', $version, $style_name); + $html[] = cssLink($name, 'light', $style_name); $ctx->styleNames[] = $style_name; if ($dark) - $html[] = cssLink($name, 'dark', $version, $style_name); + $html[] = cssLink($name, 'dark', $style_name); else if (!$config['is_dev']) - $html[] = cssPrefetchLink(str_replace('.css', '_dark.css', $name), $version); + $html[] = cssPrefetchLink(str_replace('.css', '_dark.css', $name)); } } return implode("\n", $html); } -function jsLink(string $name, $version = null): string { - if ($version !== null) - $name .= '?'.$version; - return ''; +function jsLink(string $name): string { + return ''; } -function cssLink(string $name, string $theme, $version = null, &$bname = null): string { +function cssLink(string $name, string $theme, &$bname = null): string { global $config; $dname = dirname($name); @@ -108,25 +107,33 @@ function cssLink(string $name, string $theme, $version = null, &$bname = null): $bname = substr($bname, 0, $pos); if ($config['is_dev']) { - $href = '/sass.php?name='.urlencode($bname).'&theme='.$theme; + $href = '/sass.php?name='.urlencode($bname).'&theme='.$theme.'&v='.time(); } else { - $href = $dname.'/'.$bname.($theme == 'dark' ? '_dark' : '').'.css'.($version !== null ? '?'.$version : ''); + $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, $verison = null): string { -$url = $name; -if ($verison) - $url .= '?'.$verison; -return << HTML; } +function getStaticVersion(string $name): string { + global $config; + if (str_starts_with($name, '/')) + $name = substr($name, 1); + return $config['is_dev'] ? time() : $config['static'][$name] ?? 'notfound'; +} + function renderHeader($ctx, $theme, $unsafe_logo_html) { return << -- cgit v1.2.3