From 61fa8a9b72c902b098ddb42008ec9fe1d9223a9e Mon Sep 17 00:00:00 2001 From: Neal Date: Tue, 15 Sep 2026 16:13:24 -0400 Subject: [PATCH 1/3] add test for sha-384 function --- tests/ControllerTest.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 tests/ControllerTest.php diff --git a/tests/ControllerTest.php b/tests/ControllerTest.php new file mode 100644 index 0000000..84c1cdf --- /dev/null +++ b/tests/ControllerTest.php @@ -0,0 +1,22 @@ +assertSame($expected, (new Controller())->assetVersion($path)); + } +} From beb9dec32246b7bf7f37d6065ad2ec435e947b3c Mon Sep 17 00:00:00 2001 From: Neal Date: Tue, 15 Sep 2026 16:17:54 -0400 Subject: [PATCH 2/3] add function for hashing assets --- app/Core/Controller.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/Core/Controller.php b/app/Core/Controller.php index 4373916..15b5369 100644 --- a/app/Core/Controller.php +++ b/app/Core/Controller.php @@ -11,4 +11,16 @@ public function __construct(protected $params = []) global $g_config; $this->config = $g_config; } + + public function assetVersion($path) + { + $file_path = implode(DIRECTORY_SEPARATOR, [ + realpath(ROOT), + 'public', + $path, + ]); + $algo = 'sha384'; + $version = $algo . '-' . base64_encode(hash($algo, file_get_contents($file_path), true)); + return $version; + } } From 747545c650135ffebc250de50f8a93e2e41f71da Mon Sep 17 00:00:00 2001 From: Neal Date: Tue, 15 Sep 2026 16:18:27 -0400 Subject: [PATCH 3/3] invoke asset hashing function and put into views --- app/Controllers/Findingaid.php | 18 +++++++++--------- app/Views/Euk_Shared/head-common.mustache | 4 ++-- app/Views/Layouts/application.mustache | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/Controllers/Findingaid.php b/app/Controllers/Findingaid.php index 61e140f..7e6a2a5 100644 --- a/app/Controllers/Findingaid.php +++ b/app/Controllers/Findingaid.php @@ -32,6 +32,11 @@ public function show() return; } + $css = [ + 'extra_version' => $this->assetVersion('css/extra.css'), + 'mediaelementplayer_version' => $this->assetVersion('css/mediaelementplayer.min.css'), + ]; + /* First, fill out top-level metadata, including the * table of contents. */ @@ -305,17 +310,10 @@ public function show() 'content' => $content, 'toc' => $toc, 'requests' => $requests, + 'css' => $css, 'js' => [[ 'href' => 'js/app.js', - 'hash' => hash_file('sha256', implode( - DIRECTORY_SEPARATOR, - [ - ROOT, - 'public', - 'js', - 'app.js', - ] - )), + 'version' => $this->assetVersion('js/app.js'), ]], 'title' => $model->title(), 'requestable' => $requestable, @@ -353,6 +351,7 @@ public function show() [ 'title' => $meta['title'], 'repository' => $meta['repository'], + 'css' => $css, ] ); } else { @@ -362,6 +361,7 @@ public function show() 'title' => $meta['title'], 'repository' => $meta['repository'], 'repo_url' => $repo_url, + 'css' => $css, ] ); } diff --git a/app/Views/Euk_Shared/head-common.mustache b/app/Views/Euk_Shared/head-common.mustache index 4c034ee..ff81cea 100644 --- a/app/Views/Euk_Shared/head-common.mustache +++ b/app/Views/Euk_Shared/head-common.mustache @@ -8,8 +8,8 @@ - - + + diff --git a/app/Views/Layouts/application.mustache b/app/Views/Layouts/application.mustache index 0e1a3ef..44c6983 100644 --- a/app/Views/Layouts/application.mustache +++ b/app/Views/Layouts/application.mustache @@ -47,7 +47,7 @@ {{> universal-footer}} {{> limestone-resources}} {{#js}} - + {{/js}} {{#requestable}}