From ebfa5ad7410e0d730721d3d926e7bd81f940d82f Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Fri, 19 Dec 2025 10:52:32 +0800 Subject: [PATCH] fix!: remove deprecated legacy plugin and update image handling --- apps/test/content/posts/codeblock-test.md | 2 +- hugo.toml | 3 +- layouts/_markup/render-image.html | 2 +- layouts/_partials/init/index.html | 2 +- layouts/_partials/plugin/image-legacy.html | 111 --------------------- layouts/_partials/plugin/image.html | 2 +- 6 files changed, 6 insertions(+), 116 deletions(-) delete mode 100644 layouts/_partials/plugin/image-legacy.html diff --git a/apps/test/content/posts/codeblock-test.md b/apps/test/content/posts/codeblock-test.md index b1db6597..0716863e 100644 --- a/apps/test/content/posts/codeblock-test.md +++ b/apps/test/content/posts/codeblock-test.md @@ -141,7 +141,7 @@ function add(a, b) { ## Long Code -```js +```html

Lorem ipsum dolor sit amet, graecis denique ei vel, at duo primis mandamus. Et legere ocurreret pri, animal tacimates complectitur ad cum. Cu eum inermis inimicus efficiendi. Labore officiis his ex, soluta officiis concludaturque ei qui, vide sensibus vim ad.

``` diff --git a/hugo.toml b/hugo.toml index ee083153..7163a306 100644 --- a/hugo.toml +++ b/hugo.toml @@ -1167,7 +1167,8 @@ twemoji = false # FixIt 0.2.18 | CHANGED whether to enable lightgallery # set to true, images in the content will be shown as the gallery if the image has a title, e.g. ![alt](src "title") # set to "force", images in the content will be forced to shown as the gallery regardless of the image has a title or not, e.g. ![alt](src) -lightgallery = false +# TODO change gallery engine in the future +lightgallery = true # whether to enable the ruby extended syntax ruby = true # whether to enable the fraction extended syntax diff --git a/layouts/_markup/render-image.html b/layouts/_markup/render-image.html index dfff9a1b..a2a9ca7c 100644 --- a/layouts/_markup/render-image.html +++ b/layouts/_markup/render-image.html @@ -13,7 +13,7 @@ A Markdown image has three components: the image description, the image destinat (dict "Process" "resize 1200x webp q75" "descriptor" "1200w") (dict "Process" "resize 1600x webp q75" "descriptor" "1600w") -}} -{{- if .Title | and .Text -}} +{{- if .Title -}} {{- $linked := ne $params.lightgallery false -}}
{{- dict "Src" .Destination "Alt" .PlainText "Title" .Title "Caption" .Text "Linked" $linked "Loading" "lazy" "Resources" .Page.Resources "OptimConfig" $optim | partial "plugin/image.html" -}} diff --git a/layouts/_partials/init/index.html b/layouts/_partials/init/index.html index 1c2b54d0..7ecf82c3 100644 --- a/layouts/_partials/init/index.html +++ b/layouts/_partials/init/index.html @@ -1,4 +1,4 @@ -{{- hugo.Store.Set "version" "v0.4.0-alpha.3-20251218071733-e600d047" -}} +{{- hugo.Store.Set "version" "v0.4.0-alpha.3-20251219025233-a96a76ab" -}} {{- .Store.Set "this" dict -}} {{- partial "init/detection-env.html" . -}} diff --git a/layouts/_partials/plugin/image-legacy.html b/layouts/_partials/plugin/image-legacy.html deleted file mode 100644 index 7a8c0ca4..00000000 --- a/layouts/_partials/plugin/image-legacy.html +++ /dev/null @@ -1,111 +0,0 @@ -{{- warnf "Deprecated image-legacy.html and will be removed in the next minor release, please use image.html instead." -}} -{{- $params := partial "function/params.html" -}} -{{- $class := .Class | default "" -}} -{{- $style := "" -}} -{{- $loading := .Loading | default "lazy" -}} -{{- $onload := "" -}} -{{- $onerror := "" -}} -{{- $cacheRemoteImages := $params.cacheRemoteImages -}} -{{- $suffixList := slice ".jpeg" ".jpg" ".png" ".gif" ".bmp" ".tif" ".tiff" ".webp" -}} -{{- $responsive := .Responsive -}} - -{{- if hasPrefix .Src "data:image" -}} - {{- $responsive = false -}} -{{- end -}} - -{{- /* handle for default size image */ -}} -{{- $src := .Src -}} -{{- $suffixValid := dict "Path" $src "Suffixes" $suffixList | partial "function/suffix-validation.html" -}} -{{- with dict "Path" $src "Resources" .Resources "CacheRemoteImages" $cacheRemoteImages.enable | partial "function/resource.html" -}} - {{- $url := urls.Parse $src -}} - {{- if not $url.Host | or $cacheRemoteImages.replace -}} - {{- $src = .RelPermalink -}} - {{- end -}} - {{- /* only available for image resources that are raster images */ -}} - {{- if (eq .ResourceType "image") | and $suffixValid | and $responsive -}} - {{- $style = printf "--width: %vpx;--aspect-ratio: %v / %v;" .Width .Width .Height | safeHTMLAttr -}} - {{- end -}} -{{- end -}} - -{{- $srcSmall := .SrcSmall | default $src -}} -{{- $srcMedium := $src -}} -{{- $srcLarge := .SrcLarge | default $src -}} - -{{- if $responsive }} - {{- /* handle for small size image */ -}} - {{- $suffixValidSmall := dict "Path" $srcSmall "Suffixes" $suffixList | partial "function/suffix-validation.html" -}} - {{- with dict "Path" .SrcSmall "Resources" .Resources "CacheRemoteImages" $cacheRemoteImages.enable | partial "function/resource.html" -}} - {{- $url := urls.Parse $.SrcSmall -}} - {{- if not $url.Host | or $cacheRemoteImages.replace -}} - {{- $srcSmall = .RelPermalink -}} - {{- end -}} - {{- if (eq .ResourceType "image") | and $suffixValidSmall -}} - {{- $style = printf "%v--width-small: %vpx;--aspect-ratio-small: %v / %v;" $style .Width .Width .Height | safeHTMLAttr -}} - {{- end -}} - {{- end -}} - - {{- /* handle for large size image */ -}} - {{- $suffixValidLarge := dict "Path" $srcLarge "Suffixes" $suffixList | partial "function/suffix-validation.html" -}} - {{- with dict "Path" .SrcLarge "Resources" .Resources "CacheRemoteImages" $cacheRemoteImages.enable | partial "function/resource.html" -}} - {{- $url := urls.Parse $.SrcLarge -}} - {{- if not $url.Host | or $cacheRemoteImages.replace -}} - {{- $srcLarge = .RelPermalink -}} - {{- end -}} - {{- if (eq .ResourceType "image") | and $suffixValidLarge -}} - {{- $style = printf "%v--width-large: %vpx;--aspect-ratio-large: %v / %v;" $style .Width .Width .Height | safeHTMLAttr -}} - {{- end -}} - {{- end -}} - - {{- /* handle for invalid suffix */ -}} - {{- if not $suffixValid | and $src -}} - {{- $class = printf "%v suffix-invalid" $class -}} - {{- end -}} - {{- if not $suffixValidSmall | and $srcSmall -}} - {{- $class = printf "%v suffix-invalid__small" $class -}} - {{- end -}} - {{- if not $suffixValidLarge | and $srcLarge -}} - {{- $class = printf "%v suffix-invalid__large" $class -}} - {{- end -}} - - {{- /* set image srcset */ -}} - {{- if (eq $src $srcSmall) | and (eq $src $srcLarge) -}} - {{- $srcSmall = printf (cond (strings.Contains $srcSmall "?") "%v&size=small" "%v?size=small") $srcSmall -}} - {{- $srcMedium = printf (cond (strings.Contains $srcMedium "?") "%v&size=medium" "%v?size=medium") $srcMedium -}} - {{- $srcLarge = printf (cond (strings.Contains $srcLarge "?") "%v&size=large" "%v?size=large") $srcLarge -}} - {{- end -}} -{{- end -}} - -{{- /* set image alt and caption */ -}} -{{- $alt := .Alt | default $src -}} -{{- $caption := .Caption | default $alt -}} - -{{- /* set image lazy loading */ -}} -{{- /* for details, see https://lruihao.cn/posts/native-img-loading-lazy/ */ -}} -{{- if eq $loading "lazy" -}} - {{- /* TODO move to theme.js */ -}} - {{- $commonScript := "this.title=this.dataset.title;for(const i of ['style', 'data-title','onerror','onload']){this.removeAttribute(i);}" -}} - {{- $onload = printf " onload=\"%vthis.dataset.lazyloaded='';\"" $commonScript | safeHTMLAttr -}} - {{- $onerror = printf " onerror=\"%v\"" $commonScript | safeHTMLAttr -}} - {{- $style = printf " style=\"%vbackground: url(%v) no-repeat center;\"" $style (resources.Get "images/loading.svg" | minify).RelPermalink | safeHTMLAttr -}} -{{- end -}} - -{{- /* structure of lightgallery or img */ -}} -{{- if .Linked -}} - -{{- end -}} -{{ $alt }} -{{- if .Linked -}} - -{{- end -}} diff --git a/layouts/_partials/plugin/image.html b/layouts/_partials/plugin/image.html index 163dc55e..18f788c8 100644 --- a/layouts/_partials/plugin/image.html +++ b/layouts/_partials/plugin/image.html @@ -73,7 +73,7 @@ https://github.com/HEIGE-PCloud/DoIt/blob/main/layouts/_partials/plugin/image.ht {{- end -}} {{- if .Linked -}} - + {{- end -}} {{ . }} {{- if .Linked -}}