From b3c70cedf7b21aa154c7621508aa1271950e8306 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Sun, 27 Jul 2025 00:58:08 +0800 Subject: [PATCH] chore(carosel): prevent style tag in HTML this approach does not need to change the assets or the vendor file and the live reload is also supported --- layouts/shortcodes/carousel.html | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/layouts/shortcodes/carousel.html b/layouts/shortcodes/carousel.html index b99ec2c9..1355e874 100644 --- a/layouts/shortcodes/carousel.html +++ b/layouts/shortcodes/carousel.html @@ -2,6 +2,20 @@ {{ $aspect := default "16-9" (.Get "aspectRatio") }} {{ $interval := default "2000" (.Get "interval") }} +{{ $carouselItemCSS := printf +` + #%s [data-twe-carousel-item] { + transition-duration: %sms !important; +}` $id $interval }} +{{ $carouselInitCSS := printf +` +#%s [data-twe-carousel-init] { + --twe-carousel-interval: %s; +}` $id $interval }} +{{ $cssContent := printf "%s%s" $carouselItemCSS $carouselInitCSS }} +{{ $css := resources.FromString (printf "css/carousel-%s.css" $id) $cssContent | minify | resources.Fingerprint (.Site.Params.fingerprintAlgorithm | default "sha512") }} + + {{ $page := .Page.Resources }} {{ $imagesTemp := .Get "images" }} {{ $imagesTemp = strings.TrimPrefix "{" $imagesTemp }} @@ -16,14 +30,6 @@ {{ end }} {{ end }} -