feat: use images.AutoOrient in helper/image (#1294)
* feat: use images.AutoOrient in `helper/image` closes https://github.com/CaiJimmy/hugo-theme-stack/issues/1292 * fix: check if IsImageResourceProcessable before using filter * remove local field * feat: add configurable image auto-orientation via a new `autoOrient` parameter in site configuration
This commit is contained in:
@@ -76,6 +76,8 @@ SortBy = "default"
|
|||||||
default = "auto"
|
default = "auto"
|
||||||
|
|
||||||
[imageProcessing]
|
[imageProcessing]
|
||||||
|
autoOrient = false
|
||||||
|
|
||||||
[imageProcessing.content]
|
[imageProcessing.content]
|
||||||
widths = [800, 1600, 2400]
|
widths = [800, 1600, 2400]
|
||||||
enabled = true
|
enabled = true
|
||||||
|
|||||||
@@ -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 -}}
|
{{- $alt := .PlainText | safeHTML -}}
|
||||||
{{- $title := .Title | markdownify -}}
|
{{- $title := .Title | markdownify -}}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
{{- end -}}
|
{{- end -}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{- $image := partial "helper/image" (dict "Image" .Params.image "Resources" .Resources) -}}
|
{{- $image := partial "helper/image" (dict "Image" .Params.image "Resources" .Resources "Context" .) -}}
|
||||||
{{ if $image }}
|
{{ if $image }}
|
||||||
<div class="article-image">
|
<div class="article-image">
|
||||||
{{ partial "helper/thumbnail-image" (dict
|
{{ partial "helper/thumbnail-image" (dict
|
||||||
|
|||||||
@@ -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" .) }}
|
||||||
<article class="{{ if $image }}has-image{{ end }}">
|
<article class="{{ if $image }}has-image{{ end }}">
|
||||||
{{ partial "article/components/header" (dict "Page" . "IsList" true) }}
|
{{ partial "article/components/header" (dict "Page" . "IsList" true) }}
|
||||||
</article>
|
</article>
|
||||||
@@ -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) }}
|
||||||
<article class="{{ if $image }}has-image{{ end }}">
|
<article class="{{ if $image }}has-image{{ end }}">
|
||||||
<a href="{{ .context.RelPermalink }}">
|
<a href="{{ .context.RelPermalink }}">
|
||||||
{{ if $image }}
|
{{ if $image }}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{{- $IsList := .IsList -}}
|
{{- $IsList := .IsList -}}
|
||||||
{{- $Page := .Page -}}
|
{{- $Page := .Page -}}
|
||||||
<header class="article-header">
|
<header class="article-header">
|
||||||
{{- $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 }}
|
{{ if $image }}
|
||||||
<div class="article-image">
|
<div class="article-image">
|
||||||
<a href="{{ $Page.RelPermalink }}">
|
<a href="{{ $Page.RelPermalink }}">
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
</footer>
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{- $image := partial "helper/image" (dict "Image" $link.image "Resources" $.Resources) -}}
|
{{- $image := partial "helper/image" (dict "Image" $link.image "Resources" $.Resources "Context" .) -}}
|
||||||
{{- with $image -}}
|
{{- with $image -}}
|
||||||
<div class="article-image">
|
<div class="article-image">
|
||||||
{{ partial "helper/thumbnail-image" (dict
|
{{ partial "helper/thumbnail-image" (dict
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
<link rel="{{ .Rel }}" type="{{ .MediaType.Type }}" href="{{ .Permalink | safeURL }}">
|
<link rel="{{ .Rel }}" type="{{ .MediaType.Type }}" href="{{ .Permalink | safeURL }}">
|
||||||
{{- end -}}
|
{{- 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 }}
|
{{ with $favicon }}
|
||||||
<link rel="shortcut icon" href="{{ .Permalink }}" />
|
<link rel="shortcut icon" href="{{ .Permalink }}" />
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- 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 -}}
|
{{- if $image -}}
|
||||||
<meta property='og:image' content='{{ absURL $image.permalink }}' />
|
<meta property='og:image' content='{{ absURL $image.permalink }}' />
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
<meta name="twitter:title" {{ printf "content=%q" $title | safeHTMLAttr }}>
|
<meta name="twitter:title" {{ printf "content=%q" $title | safeHTMLAttr }}>
|
||||||
<meta name="twitter:description" {{ printf "content=%q" $description | safeHTMLAttr }}>
|
<meta name="twitter:description" {{ printf "content=%q" $description | safeHTMLAttr }}>
|
||||||
|
|
||||||
{{- $image := partial "helper/image" (dict "Image" .Params.image "Resources" .Resources) -}}
|
{{- $image := partial "helper/image" (dict "Image" .Params.image "Resources" .Resources "Context" .) -}}
|
||||||
{{- if $image -}}
|
{{- if $image -}}
|
||||||
<meta name="twitter:card" content="{{ .Site.Params.opengraph.twitter.card }}">
|
<meta name="twitter:card" content="{{ .Site.Params.opengraph.twitter.card }}">
|
||||||
<meta name="twitter:image" content='{{ absURL $image.permalink }}' />
|
<meta name="twitter:image" content='{{ absURL $image.permalink }}' />
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
/// Params:
|
/// Params:
|
||||||
/// Resources: Where to search for images
|
/// Resources: Where to search for images
|
||||||
/// Image: Image URL
|
/// Image: Image URL
|
||||||
|
/// Context: page context (used to access the configuration)
|
||||||
|
|
||||||
/// Returns:
|
/// Returns:
|
||||||
/// Resource: Hugo image resource object
|
/// Resource: Hugo image resource object
|
||||||
@@ -14,6 +15,7 @@
|
|||||||
{{ $url := urls.Parse .Image }}
|
{{ $url := urls.Parse .Image }}
|
||||||
{{ $permalink := .Image }}
|
{{ $permalink := .Image }}
|
||||||
{{ $resource := "" }}
|
{{ $resource := "" }}
|
||||||
|
{{ $local := true }}
|
||||||
|
|
||||||
{{ if not (in (slice "https" "http") $url.Scheme) }}
|
{{ if not (in (slice "https" "http") $url.Scheme) }}
|
||||||
{{/* Local image */}}
|
{{/* Local image */}}
|
||||||
@@ -26,14 +28,23 @@
|
|||||||
{{ errorf "%s" . }}
|
{{ errorf "%s" . }}
|
||||||
{{ else with .Value }}
|
{{ else with .Value }}
|
||||||
{{ $resource = . }}
|
{{ $resource = . }}
|
||||||
|
{{ $local = false }}
|
||||||
{{ else }}
|
{{ else }}
|
||||||
{{ errorf "Unable to get remote resource %q" $url }}
|
{{ errorf "Unable to get remote resource %q" $url }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ with $resource }}
|
{{ if $resource }}
|
||||||
{{ if reflect.IsImageResourceWithMeta . }}
|
{{ 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
|
{{ $result = dict
|
||||||
"Resource" $resource
|
"Resource" $resource
|
||||||
"Permalink" $permalink
|
"Permalink" $permalink
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
<header>
|
<header>
|
||||||
{{ with .Site.Params.sidebar.avatar }}
|
{{ with .Site.Params.sidebar.avatar }}
|
||||||
{{- $avatar := partial "helper/image" (dict "Image" . "Resources" resources) -}}
|
{{- $avatar := partial "helper/image" (dict "Image" . "Resources" resources "Context" $) -}}
|
||||||
<figure class="site-avatar">
|
<figure class="site-avatar">
|
||||||
<a href="{{ $.Site.Home.RelPermalink }}">
|
<a href="{{ $.Site.Home.RelPermalink }}">
|
||||||
<img src="{{ $avatar.Permalink }}"
|
<img src="{{ $avatar.Permalink }}"
|
||||||
|
|||||||
+1
-1
@@ -17,7 +17,7 @@
|
|||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{- $image := partial "helper/image" (dict "Image" .Params.image "Resources" .Resources) -}}
|
{{- $image := partial "helper/image" (dict "Image" .Params.image "Resources" .Resources "Context" .) -}}
|
||||||
{{ if $image }}
|
{{ if $image }}
|
||||||
<div class="section-image">
|
<div class="section-image">
|
||||||
{{ partial "helper/thumbnail-image" (dict
|
{{ partial "helper/thumbnail-image" (dict
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
{{- range $pages -}}
|
{{- range $pages -}}
|
||||||
{{- $data := dict "title" .Title "date" .Date "permalink" .RelPermalink "content" (.Plain) -}}
|
{{- $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 -}}
|
{{- if $image -}}
|
||||||
{{- $data = merge $data (dict "image" $image.Permalink) -}}
|
{{- $data = merge $data (dict "image" $image.Permalink) -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|||||||
+1
-1
@@ -50,7 +50,7 @@
|
|||||||
{{- if .Site.Params.RSSFullContent -}}
|
{{- if .Site.Params.RSSFullContent -}}
|
||||||
{{- $content = .Content -}}
|
{{- $content = .Content -}}
|
||||||
{{- 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 -}}
|
{{- if $image -}}
|
||||||
{{- $imgTag := printf "<img src=\"%s\" alt=\"Featured image of post %s\" />" ($image.permalink | absURL) .Title -}}
|
{{- $imgTag := printf "<img src=\"%s\" alt=\"Featured image of post %s\" />" ($image.permalink | absURL) .Title -}}
|
||||||
{{- $content = printf "%s%s" $imgTag $content -}}
|
{{- $content = printf "%s%s" $imgTag $content -}}
|
||||||
|
|||||||
Reference in New Issue
Block a user