From d076ebf2e15b72aec8688274078ab09504644037 Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Sat, 27 Jun 2026 21:57:46 +0800 Subject: [PATCH] fix(layouts): fix Content+Path code path in style/script plugin partials - style.html: Content+Path now uses to-css.html for proper SCSS compilation - script.html: Content+Path now uses js-build.html with Build/Minify/Fingerprint - Both paths now update integrity hash for SRI support - script.html: restructured fallback logic to match style.html pattern --- layouts/_partials/plugin/script.html | 19 ++++++++++--------- layouts/_partials/plugin/style.html | 5 +++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/layouts/_partials/plugin/script.html b/layouts/_partials/plugin/script.html index 4599b3f9..ea5d5cce 100644 --- a/layouts/_partials/plugin/script.html +++ b/layouts/_partials/plugin/script.html @@ -24,7 +24,7 @@ {{- $src := "" -}} {{- $integrity := .Integrity -}} - {{- /* Pre-built resource */ -}} + {{- /* Resource (pre-built) */ -}} {{- with .Resource -}} {{- $src = .RelPermalink -}} {{- with .Data.Integrity -}} @@ -33,11 +33,8 @@ {{- end -}} {{- /* Source build */ -}} - {{- if not $src -}} - {{- $src = .Source -}} - {{- end -}} - {{- if $src | and (not (urls.Parse $src).Host) | and (not .Resource) -}} - {{- $resource := resources.Get $src -}} + {{- if .Source | and (not .Resource) | and (not (urls.Parse .Source).Host) -}} + {{- $resource := resources.Get .Source -}} {{- with .Template -}} {{- $resource = resources.ExecuteAsTemplate . $.Context $resource -}} {{- end -}} @@ -50,15 +47,19 @@ {{- end -}} {{- end -}} - {{- /* Script form string */ -}} + {{- /* Script from string */ -}} {{- if .Content | and .Path -}} {{- $contentResource := resources.FromString .Path .Content -}} - {{- if .Minify -}} - {{- $contentResource = $contentResource | minify -}} + {{- $contentResource = dict "Resource" $contentResource "Build" .Build "Minify" .Minify "Fingerprint" .Fingerprint | partial "function/js-build.html" -}} + {{- with .Fingerprint -}} + {{- $integrity = $contentResource.Data.Integrity -}} {{- end -}} {{- $src = $contentResource.RelPermalink -}} {{- end -}} + {{- /* Fallback to source */ -}} + {{- $src = $src | default .Source -}} + {{- /* Script attributes */ -}} {{- if $src -}} {{- $attrs := printf `src="%v"` $src -}} diff --git a/layouts/_partials/plugin/style.html b/layouts/_partials/plugin/style.html index 7d0f2acb..090a6849 100644 --- a/layouts/_partials/plugin/style.html +++ b/layouts/_partials/plugin/style.html @@ -47,8 +47,9 @@ {{- /* Style from string */ -}} {{- if .Content | and .Path -}} {{- $contentResource := resources.FromString .Path .Content -}} - {{- if .Minify -}} - {{- $contentResource = $contentResource | minify -}} + {{- $contentResource = dict "Resource" $contentResource "ToCSS" .ToCSS "Minify" .Minify "Fingerprint" .Fingerprint | partial "function/to-css.html" -}} + {{- with .Fingerprint -}} + {{- $integrity = $contentResource.Data.Integrity -}} {{- end -}} {{- $href = $contentResource.RelPermalink -}} {{- end -}}