From 8f60938e286d5b79c73b3bbdcc900aa28da2fe84 Mon Sep 17 00:00:00 2001 From: tdro Date: Sat, 4 Jun 2022 03:45:51 -0400 Subject: themes/default/layouts/_default/_markup/render-image: Cache remote images --- content/canory/messages/xkcd.md | 3 ++- .../layouts/_default/_markup/render-image.html | 25 +++++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/content/canory/messages/xkcd.md b/content/canory/messages/xkcd.md index 41ed4a6..fd3ad6a 100644 --- a/content/canory/messages/xkcd.md +++ b/content/canory/messages/xkcd.md @@ -7,7 +7,8 @@ author = "canory" Hosting and linking content is copyright radioactive. Be a good netizen and avoid hotlinking, -[but do it when it's acceptable](https://xkcd.com/license.html). +[but do it when it's acceptable](https://xkcd.com/license.html) (it's cached +anyway). ![Debugging](https://imgs.xkcd.com/comics/debugging.png " xkcd: [Debugging](https://xkcd.com/1722)" diff --git a/themes/default/layouts/_default/_markup/render-image.html b/themes/default/layouts/_default/_markup/render-image.html index fd83d75..5dcfa80 100644 --- a/themes/default/layouts/_default/_markup/render-image.html +++ b/themes/default/layouts/_default/_markup/render-image.html @@ -1,22 +1,23 @@ {{- $source := $.Destination | safeURL -}} {{- $local := print "content/" $source -}} {{- $remoteImage := resources.GetRemote $source -}} +{{- $dimensions := "600x" -}} {{- $width := "" -}} {{- $height := "" -}} +{{- $sourceFit := "" -}} {{- with $remoteImage -}} {{- with .Err -}} {{- if fileExists $local -}} - {{- $404image := imageConfig $local -}} - {{- with $404image -}} + {{- $localImage := imageConfig $local -}} + {{- with $localImage -}} {{- $width = .Width -}} {{- $height = .Height -}} {{- end -}} {{ $source = print ("" | absURL) $source }} {{- else -}} {{- $source = print "/images/404.png" -}} - {{- $local = print "static/" $source -}} - {{- $404image := imageConfig $local -}} + {{- $404image := imageConfig (print "static/" $source) -}} {{- with $404image -}} {{- $width = .Width -}} {{- $height = .Height -}} @@ -26,6 +27,7 @@ {{- else -}} {{- $width = .Width -}} {{- $height = .Height -}} + {{- $sourceFit = (.Resize $dimensions).Permalink -}} {{ end }} {{ end }} @@ -33,15 +35,22 @@
{{ $.Text | htmlUnescape }} -{{ if $.Title }} -
{{ $.Title | markdownify }}
-{{ end -}} +
+ {{ with $.Title -}} + {{ . | markdownify }} + {{ else -}} + Image/Picture + {{ end -}} +
+ {{ with $sourceFit }} Cache: {{ print "[Link](" . ")" | markdownify }} · {{ end }} + Source: {{ print "[Link](" $source ")" | markdownify }} +
{{- /* This comment removes trailing newlines and white spaces. */ -}} -- cgit v1.2.3