diff options
author | tdro <tdro@noreply.example.com> | 2022-06-04 03:45:51 -0400 |
---|---|---|
committer | tdro <tdro@noreply.example.com> | 2022-06-04 03:45:51 -0400 |
commit | 8f60938e286d5b79c73b3bbdcc900aa28da2fe84 (patch) | |
tree | 8f48915d2e0a4a55d6ca87dcfa172f49c6cf9bca | |
parent | 9a023e75ac3eadcab97222903f9b84dee0fd1f7e (diff) | |
download | canory-8f60938e286d5b79c73b3bbdcc900aa28da2fe84.tar.gz canory-8f60938e286d5b79c73b3bbdcc900aa28da2fe84.tar.bz2 canory-8f60938e286d5b79c73b3bbdcc900aa28da2fe84.zip |
themes/default/layouts/_default/_markup/render-image: Cache remote images
-rw-r--r-- | content/canory/messages/xkcd.md | 3 | ||||
-rw-r--r-- | themes/default/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 @@ <figure> <a href="{{ $source }}"> <img loading="lazy" - src="{{ $source }}" + src="{{ or $sourceFit $source }}" alt="{{ $.Text | htmlUnescape }}" title="{{ $.Text | htmlUnescape }}" width="{{ $width }}" height="{{ $height }}" /> </a> -{{ if $.Title }} - <figcaption>{{ $.Title | markdownify }}</figcaption> -{{ end -}} + <figcaption> + {{ with $.Title -}} + {{ . | markdownify }} + {{ else -}} + Image/Picture + {{ end -}} + <br> + {{ with $sourceFit }} Cache: {{ print "[Link](" . ")" | markdownify }} · {{ end }} + Source: {{ print "[Link](" $source ")" | markdownify }} + </figcaption> </figure> {{- /* This comment removes trailing newlines and white spaces. */ -}} |