feat: add image processing, improvements
This commit is contained in:
@@ -1,15 +1,21 @@
|
||||
{{- $page := . -}}
|
||||
{{- $image := "" }}
|
||||
{{- with $page.Params.headerimage }}
|
||||
<div class="header-image">
|
||||
{{- if eq $page.BundleType "leaf" }}
|
||||
{{- with $page.Resources.GetMatch .src }}
|
||||
<img src="{{ .RelPermalink }}" />
|
||||
{{- $image = . }}
|
||||
{{- end }}
|
||||
{{- else }}
|
||||
{{- with resources.GetMatch (printf "**/%s" .src) }}
|
||||
<img src="{{ .RelPermalink }}" />
|
||||
{{- $image = . }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- $processes := .processes | default (slice "fill 1000x440 webp" )}}
|
||||
{{- $image = partial "image-processing" (dict "image" $image "processes" $processes "filter" .filter) -}}
|
||||
{{- with $image }}
|
||||
<img src="{{ .RelPermalink }}" />
|
||||
{{- end }}
|
||||
{{- with .text }}<p>{{ . | markdownify }}</p>{{ end }}
|
||||
</div>
|
||||
{{- end }}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
{{- $cats := .Page.Params.categories }}
|
||||
{{- $symbols := dict "news" "🗞️" "presentation" "🎤" "podcast" "🎧" }}
|
||||
{{- $selection := "" }}
|
||||
{{- $symbols := dict "article" "🗞️" "presentation" "🎤" "podcast" "🎧" }}
|
||||
{{- $icon := "" }}
|
||||
{{- $title := "" }}
|
||||
{{- range $cat := $cats }}
|
||||
{{- with index $symbols $cat }}
|
||||
{{- $selection = (printf "%s " .) | safeHTML }}
|
||||
{{- $icon = . }}
|
||||
{{- $title = $cat | humanize }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- return $selection }}
|
||||
{{- with $icon }}
|
||||
<span title="{{ $title }}">{{ $icon }} </span>
|
||||
{{- end -}}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{{- $cats := .Page.Params.categories }}
|
||||
{{- $symbols := dict "news" "Article published" "presentation" "Presentation given" "podcast" "Podcast released" }}
|
||||
{{- $symbols := dict "article" "Article published" "presentation" "Presentation given" "podcast" "Podcast released" }}
|
||||
{{- $selection := "" }}
|
||||
{{- range $cat := $cats }}
|
||||
{{- with index $symbols $cat }}
|
||||
|
||||
32
themes/hugo-sustain/layouts/partials/image-processing.html
Normal file
32
themes/hugo-sustain/layouts/partials/image-processing.html
Normal file
@@ -0,0 +1,32 @@
|
||||
{{- /* Expects .image (resolved image resource), optionally .processes and .filter */}}
|
||||
{{- $image := .image }}
|
||||
{{- range .processes }}
|
||||
{{- $image = $image.Process . }}
|
||||
{{- end }}
|
||||
{{- with .filter }}
|
||||
{{- $filters := slice }}
|
||||
{{- range . }}
|
||||
{{- range $method, $args := . }}
|
||||
{{/* No, this cannot be generalised, as strings cannot be converted to functions... */}}
|
||||
{{- if eq $method "GaussianBlur" }}
|
||||
{{- $filters = $filters | append (images.GaussianBlur $args) }}
|
||||
{{- else if eq $method "Brightness" }}
|
||||
{{- $filters = $filters | append (images.Brightness $args) }}
|
||||
{{- else if eq $method "Opacity" }}
|
||||
{{- $filters = $filters | append (images.Opacity $args) }}
|
||||
{{- else if eq $method "Pixelate" }}
|
||||
{{- $filters = $filters | append (images.Pixelate $args) }}
|
||||
{{- else if eq $method "Saturation" }}
|
||||
{{- $filters = $filters | append (images.Saturation $args) }}
|
||||
{{- else if eq $method "Sepia" }}
|
||||
{{- $filters = $filters | append (images.Sepia $args) }}
|
||||
{{- else if eq $method "Grayscale" }}
|
||||
{{- $filters = $filters | append images.Grayscale }}
|
||||
{{- else }}
|
||||
{{- warnf "Unsupported filter: %s" $method }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- $image = $image.Filter $filters }}
|
||||
{{- end }}
|
||||
{{- return $image }}
|
||||
Reference in New Issue
Block a user