aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2022-06-07 01:48:02 -0400
committertdro <tdro@noreply.example.com>2022-06-07 01:48:02 -0400
commit04123b3bd9a7eebb1750411576ef396b2b76d29e (patch)
tree709534301175467173378b080e2432e8173356e5
parentae842407a92a6e5bba5881ac798e3603e669a892 (diff)
downloadcanory-04123b3bd9a7eebb1750411576ef396b2b76d29e.tar.gz
canory-04123b3bd9a7eebb1750411576ef396b2b76d29e.tar.bz2
canory-04123b3bd9a7eebb1750411576ef396b2b76d29e.zip
themes/default/layouts/partials/author-picture: Optimize image sizes
Didn't intend to optimize now, but public assets are available. Take easy win and reduce initial payload.
-rw-r--r--themes/default/layouts/partials/author-card.html20
-rw-r--r--themes/default/layouts/partials/author-picture.html32
2 files changed, 36 insertions, 16 deletions
diff --git a/themes/default/layouts/partials/author-card.html b/themes/default/layouts/partials/author-card.html
index 23e007a..90e7781 100644
--- a/themes/default/layouts/partials/author-card.html
+++ b/themes/default/layouts/partials/author-card.html
@@ -1,3 +1,6 @@
+{{- $path := print "public/" .Data.user "/media/profile/picture.png" -}}
+{{- $image := resources.Get $path -}}
+
<micro-author>
<micro-card>
<micro-summary>
@@ -5,13 +8,26 @@
<figure>
<a title="{{ .Data.name }}" href="{{ "" | absURL }}/{{ .Data.user }}">
<picture>
+ {{- with $image }}
+ {{- $image = .Content | resources.FromString (print "/data/static/images/" ($image | urlize)) }}
+ <source srcset="{{- ($image.Resize "x64 png").RelPermalink -}}" type="image/png" />
+ <source srcset="{{- ($image.Resize "x64 jpg").RelPermalink -}}" type="image/jpeg" />
+ <source srcset="{{- ($image.Resize "x64 webp").RelPermalink -}}" type="image/webp" />
+ {{- end }}
<img
alt="{{ .Data.name }}"
- {{- if fileExists (print "content/" .Data.user "/media/profile/picture.png") }}
- src="{{ "" | absURL }}/{{ .Data.user }}/media/profile/picture.png"
+ {{- if fileExists $path }}
+ {{ with $image }}
+ {{- $image = (.Content | resources.FromString (print "/data/static/images/" ($image | urlize))).Resize "x64" -}}
+ width="{{ $image.Width }}"
+ height="{{ $image.Height }}"
+ src="{{ $image.RelPermalink }}"
+ {{- end }}
{{ else }}
{{- $404origin := print "/images/404.png" }}
{{- $404image := imageConfig (print "static/" $404origin) }}
+ width="{{ $404image.Width }}"
+ height="{{ $404image.Height }}"
src="{{ $404origin }}"
{{- end -}}
/>
diff --git a/themes/default/layouts/partials/author-picture.html b/themes/default/layouts/partials/author-picture.html
index 88dc0df..74347fa 100644
--- a/themes/default/layouts/partials/author-picture.html
+++ b/themes/default/layouts/partials/author-picture.html
@@ -1,18 +1,18 @@
-{{- $file := "/profile/picture.png" -}}
-{{- $path := print "content/" (partial "author-media-path.html" .) $file -}}
-
+{{- $file := "/profile/picture.png" -}}
+{{- $path := print "public/" (partial "author-media-path.html" .) $file -}}
+{{- $image := resources.Get $path -}}
{{- $404origin := print "/images/404.png" -}}
-{{- $404image := imageConfig (print "static/" $404origin) -}}
+{{- $404image := imageConfig (print "static/" $404origin) -}}
-{{- if fileExists $path }}
- {{- $image := imageConfig $path -}}
- {{- with .Params.feed -}}
- {{ else }}
- <source srcset="{{ .Site.BaseURL }}/{{ partial "author-media-path.html" . }}/profile/picture.png" type="image/png" />
- <source srcset="{{ .Site.BaseURL }}/{{ partial "author-media-path.html" . }}/profile/picture.jpg" type="image/jpeg" />
- <source srcset="{{ .Site.BaseURL }}/{{ partial "author-media-path.html" . }}/profile/picture.webp" type="image/webp" />
- {{ end }}
-{{- end -}}
+{{- with .Params.feed -}}
+{{- else -}}
+ {{- with $image -}}
+ {{- $image = .Content | resources.FromString (print "/data/static/images/" ($image | urlize)) -}}
+ <source srcset="{{- ($image.Resize "x64 png").RelPermalink -}}" type="image/png" />
+ <source srcset="{{- ($image.Resize "x64 jpg").RelPermalink -}}" type="image/jpeg" />
+ <source srcset="{{- ($image.Resize "x64 webp").RelPermalink -}}" type="image/webp" />
+ {{- end -}}
+{{ end }}
<img
loading="lazy"
@@ -23,10 +23,14 @@
src="{{ .image }}"
{{ else }}
{{ if fileExists $path }}
- {{- $image := imageConfig $path -}}
+ {{- with $image -}}
+ {{- $image = (.Content | resources.FromString (print "/data/static/images/" ($image | urlize))).Resize "x64" -}}
width="{{ $image.Width }}"
height="{{ $image.Height }}"
+ src="{{ $image.RelPermalink }}"
+ {{ else -}}
src="{{ .Site.BaseURL }}/{{ partial "author-media-path.html" . }}{{ $file }}"
+ {{ end }}
{{- else -}}
width="{{ $404image.Width }}"
height="{{ $404image.Height }}"