From ee4a22d88a94a4654b7af4ebe22c821bfb80b986 Mon Sep 17 00:00:00 2001 From: elkan1788 Date: Sun, 24 Nov 2024 16:33:35 +0800 Subject: [PATCH] :art: Optimize resource fingerprint replace with unixtime for CDN. --- layouts/partials/_funs/add_unix_param.html | 4 ++++ layouts/partials/_funs/get_plugin.html | 6 +++--- layouts/partials/head/style.html | 18 ++++++++++-------- layouts/partials/scripts/global.html | 5 +++-- 4 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 layouts/partials/_funs/add_unix_param.html diff --git a/layouts/partials/_funs/add_unix_param.html b/layouts/partials/_funs/add_unix_param.html new file mode 100644 index 0000000..44db9b9 --- /dev/null +++ b/layouts/partials/_funs/add_unix_param.html @@ -0,0 +1,4 @@ +{{/** Add unix time end of link URL. **/}} +{{ $timeUnix := time.Now.Unix }} +{{ $withTimeLink := printf "%s?=%d" . $timeUnix }} +{{ return $withTimeLink }} \ No newline at end of file diff --git a/layouts/partials/_funs/get_plugin.html b/layouts/partials/_funs/get_plugin.html index e25a3ef..4b50486 100644 --- a/layouts/partials/_funs/get_plugin.html +++ b/layouts/partials/_funs/get_plugin.html @@ -5,7 +5,7 @@ {{ $plugin := resources.Get $pluginPath | resources.ExecuteAsTemplate $targetPath .ctx }} {{ if hugo.IsProduction }} -{{ $plugin = $plugin | minify | fingerprint }} +{{ $plugin = $plugin | minify }} {{ end }} - - \ No newline at end of file +{{ $unixSrc := partial "_funs/add_unix_param.html" $plugin.RelPermalink }} + \ No newline at end of file diff --git a/layouts/partials/head/style.html b/layouts/partials/head/style.html index 6faa942..0a34bfe 100644 --- a/layouts/partials/head/style.html +++ b/layouts/partials/head/style.html @@ -13,19 +13,21 @@ {{ $scss = $scss | resources.ExecuteAsTemplate "main.scss" . }} {{ $css := $scss | toCSS (dict "targetPath" "/css/main.css" "outputStyle" "expanded") }} {{ if hugo.IsProduction }} -{{ $css = $css | minify | fingerprint }} +{{ $css = $css | minify }} {{ end }} - +{{ $unixHref := partial "_funs/add_unix_param.html" $css.RelPermalink }} + {{ if .IsPage }} - + {{ end }} {{ $custom := .Scratch.Get "style" }} {{ if $custom }} - +{{ $unixHref := partial "_funs/add_unix_param.html" $custom }} + {{ end }} \ No newline at end of file diff --git a/layouts/partials/scripts/global.html b/layouts/partials/scripts/global.html index 956dd88..085c253 100644 --- a/layouts/partials/scripts/global.html +++ b/layouts/partials/scripts/global.html @@ -113,6 +113,7 @@ {{ $nextjs = $nextjs | resources.Concat "js/main.js"}} {{ if hugo.IsProduction }} -{{ $nextjs = $nextjs | minify | fingerprint }} +{{ $nextjs = $nextjs | minify }} {{ end }} - \ No newline at end of file +{{ $unixSrc := partial "_funs/add_unix_param.html" $nextjs.RelPermalink }} + \ No newline at end of file