From 1525e0712d7646e9860494f67633f4dd7c4f1157 Mon Sep 17 00:00:00 2001 From: liushuyu Date: Mon, 25 Oct 2021 03:01:56 -0600 Subject: [PATCH] layouts: use Hugo's image resizing facilities --- layouts/_default/baseof.html | 3 ++- layouts/entry/single.html | 4 +++- layouts/partials/entry/summary.html | 4 +++- layouts/shortcodes/imgs.html | 6 +++++- layouts/shortcodes/single-title-imgs-compare.html | 6 +++++- layouts/shortcodes/single-title-imgs.html | 5 ++++- 6 files changed, 22 insertions(+), 6 deletions(-) diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 1534e64..ae71fb3 100755 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -21,7 +21,8 @@ {{- if not .IsHome }}{{ .Title }} - {{ .Site.Title }}{{- else }}{{ .Site.Title }} - {{ .Site.Params.Tagline }}{{- end}} - + {{ $stylesheet := resources.Get "scss/style.scss" | toCSS | minify }} + {{- block "css" . }}{{- end }} {{ if eq (getenv "HUGO_ENV") "PRD" }} diff --git a/layouts/entry/single.html b/layouts/entry/single.html index 29a443a..3bc57a5 100644 --- a/layouts/entry/single.html +++ b/layouts/entry/single.html @@ -1,7 +1,9 @@ {{ define "header" }} +{{ $banner := (.Page.Resources.ByType "image").GetMatch "banner.png" }} +{{ $resized := $banner.Resize "1280x q99 jpg" }} {{ $author := index .Site.Data.authors ( .Params.author | default "" ) }} {{ $coauthors := split ( .Params.coauthor | default "" ) "," }} -
+
{{ .Title }} diff --git a/layouts/partials/entry/summary.html b/layouts/partials/entry/summary.html index 3148a5c..93dfb52 100644 --- a/layouts/partials/entry/summary.html +++ b/layouts/partials/entry/summary.html @@ -15,7 +15,9 @@
{{ else }} {{ $author := index .Site.Data.authors ( .Params.author | default "" ) }} -
+{{ $original := (.Page.Resources.ByType "image").GetMatch "summary.png" }} +{{ $resized := $original.Resize "1280x q90 jpg" }} +
{{ .Title }}
diff --git a/layouts/shortcodes/imgs.html b/layouts/shortcodes/imgs.html index e81337d..1361aef 100644 --- a/layouts/shortcodes/imgs.html +++ b/layouts/shortcodes/imgs.html @@ -1,3 +1,4 @@ +{{ $originals := (.Page.Resources.ByType "image") }}
{{ range $param := .Params }} @@ -15,7 +16,10 @@ {{ else }} {{- if eq $extension "png" -}} - {{ $title }} + {{ $original := $originals.GetMatch (printf "*%s" (path.Base $src)) }} + {{ $resized_width := math.Min $original.Width 1024 }} + {{ $resized := $original.Resize (print $resized_width "x q90 jpg" ) }} + {{ $title }} {{- else -}} {{ $title }} {{- end -}} diff --git a/layouts/shortcodes/single-title-imgs-compare.html b/layouts/shortcodes/single-title-imgs-compare.html index 38aed05..07d53f2 100644 --- a/layouts/shortcodes/single-title-imgs-compare.html +++ b/layouts/shortcodes/single-title-imgs-compare.html @@ -1,4 +1,5 @@ {{ $title := .Get 0 }} +{{ $originals := (.Page.Resources.ByType "image") }}