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:
@@ -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 -}}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
{{- end -}}
|
||||
</div>
|
||||
|
||||
{{- $image := partial "helper/image" (dict "Image" .Params.image "Resources" .Resources) -}}
|
||||
{{- $image := partial "helper/image" (dict "Image" .Params.image "Resources" .Resources "Context" .) -}}
|
||||
{{ if $image }}
|
||||
<div class="article-image">
|
||||
{{ 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 }}">
|
||||
{{ partial "article/components/header" (dict "Page" . "IsList" true) }}
|
||||
</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 }}">
|
||||
<a href="{{ .context.RelPermalink }}">
|
||||
{{ if $image }}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{{- $IsList := .IsList -}}
|
||||
{{- $Page := .Page -}}
|
||||
<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 }}
|
||||
<div class="article-image">
|
||||
<a href="{{ $Page.RelPermalink }}">
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
{{- $image := partial "helper/image" (dict "Image" $link.image "Resources" $.Resources) -}}
|
||||
{{- $image := partial "helper/image" (dict "Image" $link.image "Resources" $.Resources "Context" .) -}}
|
||||
{{- with $image -}}
|
||||
<div class="article-image">
|
||||
{{ partial "helper/thumbnail-image" (dict
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<link rel="{{ .Rel }}" type="{{ .MediaType.Type }}" href="{{ .Permalink | safeURL }}">
|
||||
{{- 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 }}
|
||||
<link rel="shortcut icon" href="{{ .Permalink }}" />
|
||||
{{ end }}
|
||||
|
||||
@@ -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 -}}
|
||||
<meta property='og:image' content='{{ absURL $image.permalink }}' />
|
||||
{{- end -}}
|
||||
@@ -9,7 +9,7 @@
|
||||
<meta name="twitter:title" {{ printf "content=%q" $title | 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 -}}
|
||||
<meta name="twitter:card" content="{{ .Site.Params.opengraph.twitter.card }}">
|
||||
<meta name="twitter:image" content='{{ absURL $image.permalink }}' />
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
<header>
|
||||
{{ 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">
|
||||
<a href="{{ $.Site.Home.RelPermalink }}">
|
||||
<img src="{{ $avatar.Permalink }}"
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
{{ end }}
|
||||
</div>
|
||||
|
||||
{{- $image := partial "helper/image" (dict "Image" .Params.image "Resources" .Resources) -}}
|
||||
{{- $image := partial "helper/image" (dict "Image" .Params.image "Resources" .Resources "Context" .) -}}
|
||||
{{ if $image }}
|
||||
<div class="section-image">
|
||||
{{ partial "helper/thumbnail-image" (dict
|
||||
|
||||
@@ -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 -}}
|
||||
|
||||
+1
-1
@@ -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 "<img src=\"%s\" alt=\"Featured image of post %s\" />" ($image.permalink | absURL) .Title -}}
|
||||
{{- $content = printf "%s%s" $imgTag $content -}}
|
||||
|
||||
Reference in New Issue
Block a user