From 9c1bb4c22e95a9bc185a317d0d0f74804a1d3cce Mon Sep 17 00:00:00 2001 From: Nikolaos Karaolidis Date: Thu, 11 Sep 2025 17:19:10 +0000 Subject: [PATCH] Add image processing Signed-off-by: Nikolaos Karaolidis --- assets/sass/common.scss | 18 ++++--- assets/sass/hero.scss | 2 +- layouts/_default/_markup/render-image.html | 4 +- layouts/_shortcodes/sub.html | 2 + layouts/_shortcodes/sup.html | 2 + layouts/partials/components/hero/index.html | 2 +- layouts/partials/components/image/index.html | 48 ++++++++++++++++--- .../partials/components/image/reflect.html | 31 ------------ 8 files changed, 57 insertions(+), 52 deletions(-) create mode 100644 layouts/_shortcodes/sub.html create mode 100644 layouts/_shortcodes/sup.html delete mode 100644 layouts/partials/components/image/reflect.html diff --git a/assets/sass/common.scss b/assets/sass/common.scss index bff93ef..af307b1 100644 --- a/assets/sass/common.scss +++ b/assets/sass/common.scss @@ -16,16 +16,6 @@ a:hover { color: var(--text-800); } -sup, -sub { - color: var(--text-600); -} - -sup:hover, -sub:hover { - color: var(--text-800); -} - h1, h2, h3, @@ -64,3 +54,11 @@ body { flex: 1; } } + +p { + margin: 1.5rem 0 1.5rem 0; +} + +li:not(:last-child) { + margin-bottom: 0.5rem; +} diff --git a/assets/sass/hero.scss b/assets/sass/hero.scss index badf17d..103fe83 100644 --- a/assets/sass/hero.scss +++ b/assets/sass/hero.scss @@ -1,7 +1,7 @@ .hero { max-width: $width-content; margin: 0 auto; - padding: 2rem; + padding: 2rem 2rem 0 2rem; .title { margin: 0; diff --git a/layouts/_default/_markup/render-image.html b/layouts/_default/_markup/render-image.html index 129d187..ab9646a 100644 --- a/layouts/_default/_markup/render-image.html +++ b/layouts/_default/_markup/render-image.html @@ -1,7 +1,7 @@ -{{ partial "components/image/index.html" (dict +{{ partial "components/image/index.html" (dict "page" .Page "image" (dict "src" .Destination "caption" .Text "alt" .Title - ) + )) }} {{- /* chomp trailing newline */ -}} diff --git a/layouts/_shortcodes/sub.html b/layouts/_shortcodes/sub.html new file mode 100644 index 0000000..fca3963 --- /dev/null +++ b/layouts/_shortcodes/sub.html @@ -0,0 +1,2 @@ +{{ .Get 0 | markdownify }} +{{- /* chomp trailing newline */ -}} diff --git a/layouts/_shortcodes/sup.html b/layouts/_shortcodes/sup.html new file mode 100644 index 0000000..de06743 --- /dev/null +++ b/layouts/_shortcodes/sup.html @@ -0,0 +1,2 @@ +{{ .Get 0 | markdownify }} +{{- /* chomp trailing newline */ -}} diff --git a/layouts/partials/components/hero/index.html b/layouts/partials/components/hero/index.html index 0b3c1fc..e319460 100644 --- a/layouts/partials/components/hero/index.html +++ b/layouts/partials/components/hero/index.html @@ -5,5 +5,5 @@ · {{ printf "%d MIN READ" .ReadingTime }} - {{ partial "components/image/index.html" .Params.hero }} + {{ partial "components/image/index.html" (dict "page" .Page "image" .Params.hero) }} diff --git a/layouts/partials/components/image/index.html b/layouts/partials/components/image/index.html index c5e8cd5..3c94778 100644 --- a/layouts/partials/components/image/index.html +++ b/layouts/partials/components/image/index.html @@ -1,5 +1,39 @@ -{{ $imageData := partial "components/image/reflect.html" . }} -{{- with $imageData.image -}} +{{- $page := .page -}} +{{- $image := .image -}} + +{{- $src := $image -}} +{{- $caption := "" -}} +{{- $title := "" -}} +{{- $alt := "" -}} + +{{- if reflect.IsMap $image -}} + {{- $src = $image.src | default "" -}} + {{- $caption = $image.caption | default "" -}} + {{- $title = $image.title | default $caption | default "" -}} + {{- $alt = $image.alt | default $title | default "" -}} +{{- end -}} + +{{- if $src -}} + {{- $isRemote := strings.HasPrefix $src "http" -}} + + {{- if $isRemote -}} + {{- $remote := resources.GetRemote $src -}} + {{- $image = resources.Copy (printf "static/3rd-party/%s" $remote.Name) $remote -}} + {{- else -}} + {{- $image = ($page.Resources.Get $src) | default (resources.Get $src) -}} + {{- end -}} +{{- end -}} + +{{- with $image -}} + {{ $full := . | images.Filter (images.Process "webp q90") }} + + {{ $thumb := . }} + {{- if gt .Width 2000 -}} + {{- $thumb = . | images.Filter (images.Process "resize 2000x webp q75") -}} + {{- else -}} + {{- $thumb = $full | images.Filter (images.Process "webp q75") -}} + {{- end -}} + {{- end -}} diff --git a/layouts/partials/components/image/reflect.html b/layouts/partials/components/image/reflect.html deleted file mode 100644 index 11d9398..0000000 --- a/layouts/partials/components/image/reflect.html +++ /dev/null @@ -1,31 +0,0 @@ -{{- $input := . -}} - -{{- $src := $input -}} -{{- $caption := "" -}} -{{- $title := "" -}} -{{- $alt := "" -}} - -{{- if reflect.IsMap $input -}} - {{- $src = $input.src | default "" -}} - {{- $caption = $input.caption | default "" -}} - {{- $title = $input.title | default $caption | default "" -}} - {{- $alt = $input.alt | default $title | default "" -}} -{{- end -}} - -{{ $result := dict "image" nil "caption" $caption "title" $title "alt" $alt }} - -{{- if $src -}} - {{- $isRemote := strings.HasPrefix $src "http" -}} - {{- $image := "" -}} - - {{- if $isRemote -}} - {{- $remote := resources.GetRemote $src -}} - {{- $image = resources.Copy (printf "static/3rd-party/%s" $remote.Name) $remote -}} - {{- else -}} - {{- $image = resources.Get $src -}} - {{- end -}} - - {{- $result = (dict "image" $image "caption" $caption "title" $title "alt" $alt) -}} -{{- end -}} - -{{- return $result -}}