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 --- build_static.php | 1 + skin/base.skin.php | 43 +++++++++++++++++++++++++------------------ 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/build_static.php b/build_static.php index 39b8e19..63c6e0e 100755 --- a/build_static.php +++ b/build_static.php @@ -84,6 +84,7 @@ function build_static(): void { $hashes[$name] = gethash($file); } } + logInfo($hashes); // 4. write config-static.php $scfg = "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