From 32ed9a589438a74caf5a501ad240eddd5f7ef0a3 Mon Sep 17 00:00:00 2001 From: stradichenko Date: Sun, 26 Apr 2026 15:01:30 +0200 Subject: [PATCH] Unit 10: 404 page refactor - Extract inline + {{ with resources.Get "css/404.css" }} + {{ $css404 := . | minify | fingerprint }} + + {{ end }}
-

404 Not Found

-

The page you requested cannot be found.
But hey! you found the Default Cube.

+

{{ T "NotFoundTitle" }}

+

{{ T "NotFoundMessage" }}

- Return to the home page + {{ T "NotFoundReturnHome" }}

- - -
- - - - - +
+ + {{ partial "404/vendor-script.html" (dict + "local" "js/vendor/three.min.js" + "remote" "https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js" + "name" "three.js") + }} + {{ partial "404/vendor-script.html" (dict + "local" "js/vendor/cannon.min.js" + "remote" "https://cdnjs.cloudflare.com/ajax/libs/cannon.js/0.6.2/cannon.min.js" + "name" "cannon.js") + }} + + {{/* Loaded after vendor scripts via defer ordering. */}} + {{ with resources.Get "js/404-cube.js" }} + {{ $cube := . | js.Build (dict "minify" true) | fingerprint }} + + {{ end }} {{ end }} diff --git a/layouts/partials/404/vendor-script.html b/layouts/partials/404/vendor-script.html new file mode 100644 index 0000000..625ccb2 --- /dev/null +++ b/layouts/partials/404/vendor-script.html @@ -0,0 +1,26 @@ +{{/* + Vendor script loader for the 404 page. + Loads a self-hosted copy from `assets/js/vendor/` when present, + otherwise fetches from `remote` via resources.GetRemote (Hugo computes + the SRI hash at build time). Renders nothing if neither source resolves. + + Params (dict): + local - path under assets, e.g. "js/vendor/three.min.js" + remote - full URL to fetch when local is missing + name - human label used in warnings, e.g. "three.js" +*/}} +{{ $res := resources.Get .local }} +{{ if not $res }} + {{ $remote := resources.GetRemote .remote }} + {{ if $remote }} + {{ if $remote.Err }} + {{ warnf "404: failed to fetch %s: %s" .name $remote.Err }} + {{ else }} + {{ $res = $remote }} + {{ end }} + {{ end }} +{{ end }} +{{ with $res }} + {{ $r := . | fingerprint }} + +{{ end }}