diff --git a/config/_default/params.toml b/config/_default/params.toml index f1baee3..e049622 100644 --- a/config/_default/params.toml +++ b/config/_default/params.toml @@ -76,6 +76,8 @@ SortBy = "default" default = "auto" [imageProcessing] + autoOrient = false + [imageProcessing.content] widths = [800, 1600, 2400] enabled = true diff --git a/layouts/_markup/render-image.html b/layouts/_markup/render-image.html index 2d0ebc9..8e8871b 100644 --- a/layouts/_markup/render-image.html +++ b/layouts/_markup/render-image.html @@ -1,4 +1,4 @@ -{{- $image := partial "helper/image" (dict "Resources" .Page.Resources "Image" .Destination) -}} +{{- $image := partial "helper/image" (dict "Resources" .Page.Resources "Image" .Destination "Context" .Page) -}} {{- $alt := .PlainText | safeHTML -}} {{- $title := .Title | markdownify -}} diff --git a/layouts/_partials/article-list/compact.html b/layouts/_partials/article-list/compact.html index dd6bcf5..e41f0c3 100644 --- a/layouts/_partials/article-list/compact.html +++ b/layouts/_partials/article-list/compact.html @@ -23,7 +23,7 @@ {{- end -}} - {{- $image := partial "helper/image" (dict "Image" .Params.image "Resources" .Resources) -}} + {{- $image := partial "helper/image" (dict "Image" .Params.image "Resources" .Resources "Context" .) -}} {{ if $image }}
{{ partial "helper/thumbnail-image" (dict diff --git a/layouts/_partials/article-list/default.html b/layouts/_partials/article-list/default.html index c73481e..0a1a4b0 100644 --- a/layouts/_partials/article-list/default.html +++ b/layouts/_partials/article-list/default.html @@ -1,4 +1,4 @@ -{{ $image := partial "helper/image" (dict "Image" .Params.image "Resources" .Resources) }} +{{ $image := partial "helper/image" (dict "Image" .Params.image "Resources" .Resources "Context" .) }}
{{ partial "article/components/header" (dict "Page" . "IsList" true) }}
\ No newline at end of file diff --git a/layouts/_partials/article-list/tile.html b/layouts/_partials/article-list/tile.html index 0b367af..25c15fc 100644 --- a/layouts/_partials/article-list/tile.html +++ b/layouts/_partials/article-list/tile.html @@ -1,4 +1,4 @@ -{{ $image := partial "helper/image" (dict "Image" .context.Params.image "Resources" .context.Resources) }} +{{ $image := partial "helper/image" (dict "Image" .context.Params.image "Resources" .context.Resources "Context" .context) }}
{{ if $image }} diff --git a/layouts/_partials/article/components/header.html b/layouts/_partials/article/components/header.html index 8c04d72..0d65fc5 100644 --- a/layouts/_partials/article/components/header.html +++ b/layouts/_partials/article/components/header.html @@ -1,7 +1,7 @@ {{- $IsList := .IsList -}} {{- $Page := .Page -}}
- {{- $image := partial "helper/image" (dict "Image" $Page.Params.image "Resources" $Page.Resources) -}} + {{- $image := partial "helper/image" (dict "Image" $Page.Params.image "Resources" $Page.Resources "Context" $Page) -}} {{ if $image }}
diff --git a/layouts/_partials/article/components/links.html b/layouts/_partials/article/components/links.html index 1a3dfb3..a6fa768 100644 --- a/layouts/_partials/article/components/links.html +++ b/layouts/_partials/article/components/links.html @@ -15,7 +15,7 @@
- {{- $image := partial "helper/image" (dict "Image" $link.image "Resources" $.Resources) -}} + {{- $image := partial "helper/image" (dict "Image" $link.image "Resources" $.Resources "Context" .) -}} {{- with $image -}}
{{ partial "helper/thumbnail-image" (dict diff --git a/layouts/_partials/head/head.html b/layouts/_partials/head/head.html index 53cc317..00f31d5 100644 --- a/layouts/_partials/head/head.html +++ b/layouts/_partials/head/head.html @@ -23,7 +23,7 @@ {{- end -}} -{{- $favicon := partial "helper/image" (dict "Image" .Site.Params.favicon "Resources" resources) -}} +{{- $favicon := partial "helper/image" (dict "Image" .Site.Params.favicon "Resources" resources "Context" .) -}} {{ with $favicon }} {{ end }} diff --git a/layouts/_partials/head/opengraph/provider/base.html b/layouts/_partials/head/opengraph/provider/base.html index 135c60c..358a636 100644 --- a/layouts/_partials/head/opengraph/provider/base.html +++ b/layouts/_partials/head/opengraph/provider/base.html @@ -37,7 +37,7 @@ {{- end -}} {{- end -}} -{{ $image := partial "helper/image" (dict "Image" .Params.image "Resources" .Resources) }} +{{ $image := partial "helper/image" (dict "Image" .Params.image "Resources" .Resources "Context" .) }} {{- if $image -}} {{- end -}} \ No newline at end of file diff --git a/layouts/_partials/head/opengraph/provider/twitter.html b/layouts/_partials/head/opengraph/provider/twitter.html index 6f7b78a..1d9b650 100644 --- a/layouts/_partials/head/opengraph/provider/twitter.html +++ b/layouts/_partials/head/opengraph/provider/twitter.html @@ -9,7 +9,7 @@ -{{- $image := partial "helper/image" (dict "Image" .Params.image "Resources" .Resources) -}} +{{- $image := partial "helper/image" (dict "Image" .Params.image "Resources" .Resources "Context" .) -}} {{- if $image -}} diff --git a/layouts/_partials/helper/image.html b/layouts/_partials/helper/image.html index c2646b0..36a7480 100644 --- a/layouts/_partials/helper/image.html +++ b/layouts/_partials/helper/image.html @@ -1,6 +1,7 @@ /// Params: /// Resources: Where to search for images /// Image: Image URL +/// Context: page context (used to access the configuration) /// Returns: /// Resource: Hugo image resource object @@ -14,6 +15,7 @@ {{ $url := urls.Parse .Image }} {{ $permalink := .Image }} {{ $resource := "" }} + {{ $local := true }} {{ if not (in (slice "https" "http") $url.Scheme) }} {{/* Local image */}} @@ -26,14 +28,23 @@ {{ errorf "%s" . }} {{ else with .Value }} {{ $resource = . }} + {{ $local = false }} {{ else }} {{ errorf "Unable to get remote resource %q" $url }} {{ end }} {{ end }} {{ end }} - {{ with $resource }} - {{ if reflect.IsImageResourceWithMeta . }} + {{ if $resource }} + {{ if and .Context.Site.Params.imageProcessing.autoOrient (reflect.IsImageResourceProcessable $resource) }} + {{ $filter := images.AutoOrient }} + {{ $resource = $resource | images.Filter $filter }} + {{ if $local }} + {{ $permalink = $resource.RelPermalink }} + {{ end }} + {{ end }} + + {{ if reflect.IsImageResourceWithMeta $resource }} {{ $result = dict "Resource" $resource "Permalink" $permalink diff --git a/layouts/_partials/sidebar/left.html b/layouts/_partials/sidebar/left.html index b007e49..8319a49 100644 --- a/layouts/_partials/sidebar/left.html +++ b/layouts/_partials/sidebar/left.html @@ -7,7 +7,7 @@
{{ with .Site.Params.sidebar.avatar }} - {{- $avatar := partial "helper/image" (dict "Image" . "Resources" resources) -}} + {{- $avatar := partial "helper/image" (dict "Image" . "Resources" resources "Context" $) -}}
- {{- $image := partial "helper/image" (dict "Image" .Params.image "Resources" .Resources) -}} + {{- $image := partial "helper/image" (dict "Image" .Params.image "Resources" .Resources "Context" .) -}} {{ if $image }}
{{ partial "helper/thumbnail-image" (dict diff --git a/layouts/page/search.json b/layouts/page/search.json index 87bf070..e69868d 100644 --- a/layouts/page/search.json +++ b/layouts/page/search.json @@ -4,7 +4,7 @@ {{- range $pages -}} {{- $data := dict "title" .Title "date" .Date "permalink" .RelPermalink "content" (.Plain) -}} - {{- $image := partial "helper/image" (dict "Image" .Params.image "Resources" .Resources) -}} + {{- $image := partial "helper/image" (dict "Image" .Params.image "Resources" .Resources "Context" .) -}} {{- if $image -}} {{- $data = merge $data (dict "image" $image.Permalink) -}} {{- end -}} diff --git a/layouts/rss.xml b/layouts/rss.xml index 8d6d2b9..6b65a08 100644 --- a/layouts/rss.xml +++ b/layouts/rss.xml @@ -50,7 +50,7 @@ {{- if .Site.Params.RSSFullContent -}} {{- $content = .Content -}} {{- end -}} - {{- $image := partial "helper/image" (dict "Image" .Params.image "Resources" .Resources) -}} + {{- $image := partial "helper/image" (dict "Image" .Params.image "Resources" .Resources "Context" .) -}} {{- if $image -}} {{- $imgTag := printf "\"Featured" ($image.permalink | absURL) .Title -}} {{- $content = printf "%s%s" $imgTag $content -}}