mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-07-19 18:45:30 -04:00
make optimize-image more function-like
....instead of relying on $.Scratch
This commit is contained in:
@@ -1,25 +1,25 @@
|
||||
{{- /* Automatic resizing for HiDPI/retina images */ -}}
|
||||
{{/* Automatic resizing for HiDPI/retina images */}}
|
||||
|
||||
{{- $original := .Page.Resources.GetMatch (.Get "src") -}}
|
||||
{{- .Scratch.Set "image" $original -}}
|
||||
{{ $original := .Page.Resources.GetMatch (.Get "src") }}
|
||||
{{ .Scratch.Set "image" $original }}
|
||||
|
||||
{{- $setWidth := 910 -}}
|
||||
{{ $setWidth := 910 }}
|
||||
|
||||
{{- if .Get "width" -}}
|
||||
{{- $setWidth = (int (.Get "width")) -}}
|
||||
{{- end -}}
|
||||
{{ if .Get "width" }}
|
||||
{{ $setWidth = (int (.Get "width")) }}
|
||||
{{ end }}
|
||||
|
||||
{{- $retinaWidth := (mul $setWidth 2) -}}
|
||||
{{ $retinaWidth := (mul $setWidth 2) }}
|
||||
|
||||
{{- if gt $original.Width $retinaWidth -}}
|
||||
{{- $finalWidth := (printf "%dx" $retinaWidth) -}}
|
||||
{{- .Scratch.Set "image" ($original.Resize $finalWidth) -}}
|
||||
{{- end -}}
|
||||
{{ if gt $original.Width $retinaWidth -}}
|
||||
{{ $finalWidth := (printf "%dx" $retinaWidth) }}
|
||||
{{ .Scratch.Set "image" ($original.Resize $finalWidth) }}
|
||||
{{ end }}
|
||||
|
||||
{{- $image := .Scratch.Get "image" -}}
|
||||
{{ $image := .Scratch.Get "image" }}
|
||||
|
||||
{{- $origRatio := (div (float $image.Height) $image.Width) -}}
|
||||
{{- .Scratch.Set "displayWidth" $setWidth -}}
|
||||
{{- .Scratch.Set "displayHeight" (math.Ceil (mul $origRatio $setWidth)) -}}
|
||||
{{ $origRatio := (div (float $image.Height) $image.Width) }}
|
||||
{{ $displayWidth := $setWidth }}
|
||||
{{ $displayHeight := (math.Ceil (mul $origRatio $setWidth)) }}
|
||||
|
||||
{{- return $image -}}
|
||||
{{ return (dict "Permalink" $image.Permalink "Width" $displayWidth "Height" $displayHeight) }}
|
||||
|
Reference in New Issue
Block a user