summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2022-07-11 00:14:21 +0300
committerEvgeny Zinoviev <me@ch1p.io>2022-07-11 00:33:15 +0300
commit5eecaffdef97aa938fcbc455ec02e52d08d5af29 (patch)
tree3411185e0f1916ff13b1f2e353ad00fd1dc6e71d
parent8209144cdfdeb0028badbea3fe81a2dc5a5ec03f (diff)
skin/base: fix static version rendering
-rwxr-xr-xbuild_static.php1
-rw-r--r--skin/base.skin.php43
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 = "<?php\n\n";
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 '<script src="'.$name.'" type="text/javascript"></script>';
+function jsLink(string $name): string {
+ return '<script src="'.$name.'?'.getStaticVersion($name).'" type="text/javascript"></script>';
}
-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).'&amp;theme='.$theme;
+ $href = '/sass.php?name='.urlencode($bname).'&amp;theme='.$theme.'&amp;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 '<link rel="stylesheet" id="'.$id.'" type="text/css" href="'.$href.'">';
}
-function cssPrefetchLink(string $name, $verison = null): string {
-$url = $name;
-if ($verison)
- $url .= '?'.$verison;
-return <<<HTML
+function cssPrefetchLink(string $name): string {
+ $url = $name.'?'.getStaticVersion($name);
+ return <<<HTML
<link rel="prefetch" href="{$url}" />
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 <<<HTML
<div class="head base-width">