Skip to content

Commit

Permalink
feat: article image now supports svg format
Browse files Browse the repository at this point in the history
tomowang committed Apr 29, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 7a682e9 commit 25c009b
Showing 4 changed files with 18 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions exampleSite/content/post/image-process/index.md
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ date = "2023-12-01"
description = "Demo of Hugo's image processing"
tags = []
toc = false
image = "images/hugo-logo-wide.svg"
+++

![Photo by Behnam Norouzi on Unsplash](./images/behnam-norouzi-_1ok63FFlM4-unsplash.jpg "Photo by Behnam Norouzi on Unsplash")
1 change: 1 addition & 0 deletions exampleSite/content/post/image-process/index.zh-cn.md
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@ date = "2023-12-01"
description = "关于Hugo中图片处理的示例"
tags = []
toc = false
image = "images/hugo-logo-wide.svg"
+++

![Photo by Behnam Norouzi on Unsplash](./images/behnam-norouzi-_1ok63FFlM4-unsplash.jpg "Photo by Behnam Norouzi on Unsplash")
9 changes: 9 additions & 0 deletions layouts/partials/block/image.html
Original file line number Diff line number Diff line change
@@ -8,6 +8,14 @@
{{- $dest = path.Join (path.Dir $dest) (path.Base $dest) -}}

{{- with .Resources.Get $dest -}}
{{- if eq .MediaType.SubType "svg" -}}
<figure>
<img class="w-full object-cover h-36 md:h-48 xl:h-60" src="{{ .RelPermalink }}"
alt="{{ $alt }}" title="{{ $alt }}"
loading="lazy"
>
</figure>
{{- else -}}
{{- $src := . -}}
{{- $dataSzes := "(min-width: 1024px) 100vw, 50vw" -}}
{{- $actualImg := $src.Resize (print "640x jpg " $filter) -}}
@@ -30,6 +38,7 @@
{{- end -}}" sizes="{{ $dataSzes }}" />
<img class="w-full object-cover h-36 md:h-48 xl:h-60" src="{{ $actualImg.RelPermalink }}" width="{{ $src.Width }}" height="{{ $src.Height }}" alt="{{ $alt }}" title="{{ $alt }}" loading="lazy" />
</picture>
{{- end -}}
<!-- or otherwise simply load the URL -->
{{- else -}}
<figure>

0 comments on commit 25c009b

Please sign in to comment.