diff --git a/config/_default/params.toml b/config/_default/params.toml index f1baee3f..e049622a 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 2d0ebc96..8e8871b8 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 dd6bcf52..e41f0c39 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 c73481e3..0a1a4b05 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 0b367af0..25c15fc3 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 8c04d72a..0d65fc59 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 1a3dfb30..a6fa7686 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 53cc3179..00f31d57 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 135c60c1..358a6368 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 6f7b78a4..1d9b6508 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 c2646b07..36a74807 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 b007e49b..8319a494 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 87bf0700..e69868d3 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 8d6d2b97..6b65a081 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 -}}