diff options
author | mms <michal@sapka.me> | 2024-06-04 22:53:01 +0200 |
---|---|---|
committer | mms <michal@sapka.me> | 2024-06-04 22:53:01 +0200 |
commit | 66209e7dfff41ca73cdf76bd08b852b088e0b6fc (patch) | |
tree | 51caacdb65969f4ead0f635500120e0756abe6ed /layouts | |
parent | dd7b51f0c1c3ad5e907b06621ea76c01f5e5e5ec (diff) |
wip: unix hist 3
Diffstat (limited to 'layouts')
-rw-r--r-- | layouts/shortcodes/image.html | 53 | ||||
-rw-r--r-- | layouts/unix-history/baseof.html | 3 |
2 files changed, 54 insertions, 2 deletions
diff --git a/layouts/shortcodes/image.html b/layouts/shortcodes/image.html new file mode 100644 index 0000000..441c2d1 --- /dev/null +++ b/layouts/shortcodes/image.html @@ -0,0 +1,53 @@ +<!-- Read page and image params --> +{{- $max_width := .Page.Params.image_max_width }} +{{- $dir := .Page.Params.image_dir }} + +{{- $caption := .Inner }} +{{- $file := .Params.file }} +{{- $class := .Params.class }} +{{- $source := .Params.source }} +{{- $alt := .Params.alt }} + +<!-- Get the the image --> +{{- $path := printf "%s/%s" $dir $file}} +{{- $img := resources.Get $path }} + +<!-- Decide on the desired 1x and 2x width --> +{{- $raw_width := $img.Width}} +{{- $final1x_width := (cond (gt $max_width $raw_width) $raw_width $max_width) }} +{{- $final2x_width := math.Mul $final1x_width 2}} + +<!-- Generate 1x and 2x images --> +{{- $img1xproc := printf "x%d webp q90" $final1x_width }} +{{- $img2xproc := printf "x%d webp q90" $final2x_width }} +{{- $img1x := $img.Resize $img1xproc }} +{{- $img2x := $img.Resize $img2xproc }} + +<!-- Generate raw, optimized img --> +{{- $imgproc := printf "x%d webp q90" $raw_width }} +{{- $img_raw := $img.Resize $imgproc }} + +<!-- Resulting HTML --> +<figure> + <a href="{{ $img_raw.Permalink }}"> + <img + class="{{ $class }}" + alt="{{ $alt }}" + src="{{ $img1x.Permalink }}" + srcset=" + {{ $img1x.Permalink }} 1x, + {{ $img2x.Permalink }} 2x + " + width="{{ $img1x.Width }}" + height="{{ $img1x.Height }}" + > + </a> + <figcaption> + {{ $caption }} + + {{- if $source }} + <a href="{{ $source }}" target="_blank" title="source">[source]</a> + {{ end }} + </figcaption> +</figure> + diff --git a/layouts/unix-history/baseof.html b/layouts/unix-history/baseof.html index 396f391..e9ea254 100644 --- a/layouts/unix-history/baseof.html +++ b/layouts/unix-history/baseof.html @@ -110,7 +110,6 @@ <body> <header> - <nav> {{ range $parent := first 1 .Ancestors}} <a href="{{ .Permalink }}"> < Back</a> @@ -136,7 +135,7 @@ <hr> <footer> Website created and operated by <a href="https://michal.sapka.me">MichaĆ</a> - <!-- <div style="padding: 15px; text-align: center;"> --> + <div style="padding: 15px; text-align: center;"> {{ partial "buttons/valid_html" . }} </div> </footer> |