From 3be0e8474d2149471293ef1aaa30a4d2dbb1d43b Mon Sep 17 00:00:00 2001 From: "E. S." Date: Wed, 13 Mar 2024 01:27:35 +0000 Subject: [PATCH] config-static: support integrity --- deploy/gen_static_config.php | 13 +++++++++---- engine/skin.php | 2 ++ skin/base.phps | 13 ++++++++++--- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/deploy/gen_static_config.php b/deploy/gen_static_config.php index f83c547..dca6f87 100755 --- a/deploy/gen_static_config.php +++ b/deploy/gen_static_config.php @@ -1,9 +1,8 @@ #!/usr/bin/env php get_hash($file), + 'integrity' => [] + ]; + foreach (RESOURCE_INTEGRITY_HASHES as $hash_type) + $hashes[$type.'/'.basename($file)]['integrity'][$hash_type] = base64_encode(hash_file($hash_type, $file, true)); + } } echo "'; + return ''; } function cssLink(string $name, string $theme, &$bname = null): string { @@ -165,7 +165,7 @@ function cssLink(string $name, string $theme, &$bname = null): string { if ($theme == 'dark') $id .= '_dark'; - return ''; + return ''; } function cssPrefetchLink(string $name): string { @@ -195,7 +195,14 @@ function getStaticVersion(string $name): string { logWarning(__FUNCTION__.': '.$name.' starts with /'); $name = substr($name, 1); } - return $config['static'][$name] ?? 'notfound'; + return $config['static'][$name]['version'] ?? 'notfound'; +} + +function getStaticIntegrityAttribute(string $name): string { + if (is_dev()) + return ''; + global $config; + return ' integrity="'.implode(' ', array_map(fn($hash_type) => $hash_type.'-'.$config['static'][$name]['integrity'][$hash_type], RESOURCE_INTEGRITY_HASHES)).'"'; }