Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/_default/params.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ SortBy = "default"
default = "auto"

[imageProcessing]
autoOrient = false

[imageProcessing.content]
widths = [800, 1600, 2400]
enabled = true
Expand Down
2 changes: 1 addition & 1 deletion layouts/_markup/render-image.html
Original file line number Diff line number Diff line change
@@ -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 -}}

Expand Down
2 changes: 1 addition & 1 deletion layouts/_partials/article-list/compact.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h2 class="article-title">
{{- 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
Expand Down
2 changes: 1 addition & 1 deletion layouts/_partials/article-list/default.html
Original file line number Diff line number Diff line change
@@ -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>
2 changes: 1 addition & 1 deletion layouts/_partials/article-list/tile.html
Original file line number Diff line number Diff line change
@@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion layouts/_partials/article/components/header.html
Original file line number Diff line number Diff line change
@@ -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 }}">
Expand Down
2 changes: 1 addition & 1 deletion layouts/_partials/article/components/links.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h2 class="article-title">
</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
Expand Down
2 changes: 1 addition & 1 deletion layouts/_partials/head/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion layouts/_partials/head/opengraph/provider/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
2 changes: 1 addition & 1 deletion layouts/_partials/head/opengraph/provider/twitter.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}' />
Expand Down
15 changes: 13 additions & 2 deletions layouts/_partials/helper/image.html
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -14,6 +15,7 @@
{{ $url := urls.Parse .Image }}
{{ $permalink := .Image }}
{{ $resource := "" }}
{{ $local := true }}

{{ if not (in (slice "https" "http") $url.Scheme) }}
{{/* Local image */}}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion layouts/_partials/sidebar/left.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down
2 changes: 1 addition & 1 deletion layouts/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h2 class="section-description">{{ . }}</h2>
{{ 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
Expand Down
2 changes: 1 addition & 1 deletion layouts/page/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/rss.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
Expand Down
Loading