mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-07-17 19:25:32 -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") -}}
|
{{ $original := .Page.Resources.GetMatch (.Get "src") }}
|
||||||
{{- .Scratch.Set "image" $original -}}
|
{{ .Scratch.Set "image" $original }}
|
||||||
|
|
||||||
{{- $setWidth := 910 -}}
|
{{ $setWidth := 910 }}
|
||||||
|
|
||||||
{{- if .Get "width" -}}
|
{{ if .Get "width" }}
|
||||||
{{- $setWidth = (int (.Get "width")) -}}
|
{{ $setWidth = (int (.Get "width")) }}
|
||||||
{{- end -}}
|
{{ end }}
|
||||||
|
|
||||||
{{- $retinaWidth := (mul $setWidth 2) -}}
|
{{ $retinaWidth := (mul $setWidth 2) }}
|
||||||
|
|
||||||
{{- if gt $original.Width $retinaWidth -}}
|
{{ if gt $original.Width $retinaWidth -}}
|
||||||
{{- $finalWidth := (printf "%dx" $retinaWidth) -}}
|
{{ $finalWidth := (printf "%dx" $retinaWidth) }}
|
||||||
{{- .Scratch.Set "image" ($original.Resize $finalWidth) -}}
|
{{ .Scratch.Set "image" ($original.Resize $finalWidth) }}
|
||||||
{{- end -}}
|
{{ end }}
|
||||||
|
|
||||||
{{- $image := .Scratch.Get "image" -}}
|
{{ $image := .Scratch.Get "image" }}
|
||||||
|
|
||||||
{{- $origRatio := (div (float $image.Height) $image.Width) -}}
|
{{ $origRatio := (div (float $image.Height) $image.Width) }}
|
||||||
{{- .Scratch.Set "displayWidth" $setWidth -}}
|
{{ $displayWidth := $setWidth }}
|
||||||
{{- .Scratch.Set "displayHeight" (math.Ceil (mul $origRatio $setWidth)) -}}
|
{{ $displayHeight := (math.Ceil (mul $origRatio $setWidth)) }}
|
||||||
|
|
||||||
{{- return $image -}}
|
{{ return (dict "Permalink" $image.Permalink "Width" $displayWidth "Height" $displayHeight) }}
|
||||||
|
@@ -5,4 +5,6 @@
|
|||||||
<link rel="icon" href="{{ (printf "favicon-%v.png" .) | absURL }}" sizes="{{ . }}x{{ . }}">
|
<link rel="icon" href="{{ (printf "favicon-%v.png" .) | absURL }}" sizes="{{ . }}x{{ . }}">
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
|
|
||||||
<link rel="shortcut icon" href="{{ "favicon.ico" | absURL }}" sizes="{{ .ico_sizes }}">
|
{{ $s := slice -}}
|
||||||
|
{{ range (split .ico_sizes " ") }}{{ $s = $s | append (printf "%vx%v" . .) }}{{ end -}}
|
||||||
|
<link rel="shortcut icon" href="{{ "favicon.ico" | absURL }}" sizes="{{ delimit $s " " }}">
|
||||||
|
@@ -1,22 +1,22 @@
|
|||||||
{{ partial "head/meta" . }}
|
{{ partial "head/meta" . -}}
|
||||||
{{ partial "head/social-images" . }}
|
{{ partial "head/social-images" . -}}
|
||||||
{{ partial "head/open-graph" . }}
|
{{ partial "head/open-graph" . -}}
|
||||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||||
<meta name="apple-mobile-web-app-status-bar-style" content="default">
|
<meta name="apple-mobile-web-app-status-bar-style" content="default">
|
||||||
<meta name="apple-mobile-web-app-title" content="{{ .Site.Title }}">
|
<meta name="apple-mobile-web-app-title" content="{{ .Site.Title }}">
|
||||||
<meta name="theme-color" content="#0e6dc2">
|
<meta name="theme-color" content="#0e6dc2">
|
||||||
{{ partialCached "head/preload" . }}
|
{{ partialCached "head/preload" . -}}
|
||||||
{{ partialCached "head/styles" . }}
|
{{ partialCached "head/styles" . -}}
|
||||||
{{ partialCached "head/favicons" (dict "png_sizes" "192 48 32 16" "ico_sizes" "16x16 32x32 48x48") }}
|
{{ partialCached "head/favicons" (dict "png_sizes" "192 48 32 16" "ico_sizes" "16 32 48") -}}
|
||||||
<link rel="canonical" href="{{ .Permalink }}">
|
<link rel="canonical" href="{{ .Permalink }}">
|
||||||
<link rel="alternate" type="application/rss+xml" href="{{ "feed.xml" | absURL }}" title="{{ .Site.Title }} (RSS)">
|
<link rel="alternate" type="application/rss+xml" href="{{ "feed.xml" | absURL }}" title="{{ .Site.Title }} (RSS)">
|
||||||
<link rel="author" href="{{ "humans.txt" | absURL }}">
|
<link rel="author" href="{{ "humans.txt" | absURL }}">
|
||||||
{{ if and .IsPage (eq .Type "notes") }}
|
{{ if and .IsPage (eq .Type "notes") }}
|
||||||
{{ with .OutputFormats.Get "amp" }}
|
{{- with .OutputFormats.Get "amp" -}}
|
||||||
<link rel="amphtml" href="{{ .Permalink }}">
|
<link rel="amphtml" href="{{ .Permalink }}">
|
||||||
{{ end }}
|
{{- end }}
|
||||||
{{ partial "head/schema-person" . }}
|
{{ partial "head/schema-person" . }}
|
||||||
{{ partial "head/schema-article" . }}
|
{{ partial "head/schema-article" . }}
|
||||||
{{ else }}
|
{{ else }}
|
||||||
{{ partial "head/schema-person" . }}
|
{{ partial "head/schema-person" . }}
|
||||||
{{ end }}
|
{{ end -}}
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
{{- /* Default image */ -}}
|
{{/* Default image */}}
|
||||||
{{- $defaultImagePath := (path.Join "content" $.Site.Params.defaultimage) }}
|
{{- $defaultImagePath := (path.Join "content" $.Site.Params.defaultimage) }}
|
||||||
{{- $.Scratch.Set "defaultImage_url" (replace $defaultImagePath "content/" $.Site.BaseURL) }}
|
{{ $.Scratch.Set "defaultImage_url" (replace $defaultImagePath "content/" $.Site.BaseURL) }}
|
||||||
{{- with (imageConfig $defaultImagePath) }}
|
{{ with (imageConfig $defaultImagePath) }}
|
||||||
{{- $.Scratch.Set "defaultImage_width" .Width }}
|
{{- $.Scratch.Set "defaultImage_width" .Width }}
|
||||||
{{- $.Scratch.Set "defaultImage_height" .Height }}
|
{{- $.Scratch.Set "defaultImage_height" .Height }}
|
||||||
{{- end }}
|
{{ end -}}
|
||||||
|
|
||||||
{{- /* Article image (with fallback to default image */ -}}
|
{{/* Article image (with fallback to default image */}}
|
||||||
{{- with .Params.image }}
|
{{- with .Params.image }}
|
||||||
{{- $imagePath := (path.Join "content" $.File.Dir "images/" .) }}
|
{{- $imagePath := (path.Join "content" $.File.Dir "images/" .) }}
|
||||||
|
|
||||||
@@ -15,18 +15,18 @@
|
|||||||
{{- $.Scratch.Set "socialImage_width" .Width }}
|
{{- $.Scratch.Set "socialImage_width" .Width }}
|
||||||
{{- $.Scratch.Set "socialImage_height" .Height }}
|
{{- $.Scratch.Set "socialImage_height" .Height }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- else }}
|
{{ else }}
|
||||||
{{- $.Scratch.Set "socialImage_url" (replace $defaultImagePath "content/" $.Site.BaseURL) }}
|
{{- $.Scratch.Set "socialImage_url" (replace $defaultImagePath "content/" $.Site.BaseURL) }}
|
||||||
{{- with (imageConfig $defaultImagePath) }}
|
{{- with (imageConfig $defaultImagePath) }}
|
||||||
{{- $.Scratch.Set "socialImage_width" .Width }}
|
{{- $.Scratch.Set "socialImage_width" .Width }}
|
||||||
{{- $.Scratch.Set "socialImage_height" .Height }}
|
{{- $.Scratch.Set "socialImage_height" .Height }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{ end -}}
|
||||||
|
|
||||||
{{- /* Site logo */ -}}
|
{{/* Site logo */}}
|
||||||
{{- $logoImagePath := (path.Join "content" "logo.png") }}
|
{{- $logoImagePath := (path.Join "content" "logo.png") }}
|
||||||
{{- $.Scratch.Set "logoImage_url" (replace $logoImagePath "content/" $.Site.BaseURL) }}
|
{{ $.Scratch.Set "logoImage_url" (replace $logoImagePath "content/" $.Site.BaseURL) }}
|
||||||
{{- with (imageConfig $logoImagePath) }}
|
{{ with (imageConfig $logoImagePath) }}
|
||||||
{{- $.Scratch.Set "logoImage_width" .Width }}
|
{{- $.Scratch.Set "logoImage_width" .Width }}
|
||||||
{{- $.Scratch.Set "logoImage_height" .Height }}
|
{{- $.Scratch.Set "logoImage_height" .Height }}
|
||||||
{{- end }}
|
{{ end -}}
|
||||||
|
@@ -3,10 +3,10 @@
|
|||||||
<p class="image">
|
<p class="image">
|
||||||
<amp-img
|
<amp-img
|
||||||
{{- with .Get "alt" }} alt="{{ . | safeHTML }}" title="{{ . | safeHTML }}"{{ else }}
|
{{- with .Get "alt" }} alt="{{ . | safeHTML }}" title="{{ . | safeHTML }}"{{ else }}
|
||||||
{{- with .Inner }} alt="{{ . | markdownify | plainify | safeHTML }}" title="{{ . | markdownify | plainify | safeHTML }}"{{ end }}{{ end }}
|
{{- with .Inner }} alt="{{ . | $.Page.RenderString | plainify | safeHTML }}" title="{{ . | $.Page.RenderString | plainify | safeHTML }}"{{ end }}{{ end }}
|
||||||
src="{{ $optimized.Permalink }}"
|
src="{{ $optimized.Permalink }}"
|
||||||
width="{{ .Scratch.Get "displayWidth" }}"
|
width="{{ $optimized.Width }}"
|
||||||
height="{{ .Scratch.Get "displayHeight" }}"
|
height="{{ $optimized.Height }}"
|
||||||
layout="intrinsic">
|
layout="intrinsic">
|
||||||
</amp-img>
|
</amp-img>
|
||||||
</p>
|
</p>
|
||||||
|
@@ -3,12 +3,12 @@
|
|||||||
{{- with .Inner }}
|
{{- with .Inner }}
|
||||||
<figure>
|
<figure>
|
||||||
<picture>
|
<picture>
|
||||||
<img src="{{ $optimized.Permalink }}" width="{{ $.Scratch.Get "displayWidth" }}" height="{{ $.Scratch.Get "displayHeight" }}"
|
<img src="{{ $optimized.Permalink }}" width="{{ $optimized.Width }}" height="{{ $optimized.Height }}"
|
||||||
alt="{{ . | markdownify | plainify | safeHTML }}" title="{{ . | markdownify | plainify | safeHTML }}">
|
alt="{{ . | $.Page.RenderString | plainify | safeHTML }}" title="{{ . | $.Page.RenderString | plainify | safeHTML }}">
|
||||||
</picture>
|
</picture>
|
||||||
<figcaption>{{ . | $.Page.RenderString | safeHTML }}</figcaption>
|
<figcaption>{{ . | $.Page.RenderString | safeHTML }}</figcaption>
|
||||||
</figure>
|
</figure>
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
<p><img src="{{ $optimized.Permalink }}" width="{{ $.Scratch.Get "displayWidth" }}" height="{{ $.Scratch.Get "displayHeight" }}"
|
<p><img src="{{ $optimized.Permalink }}" width="{{ $optimized.Width }}" height="{{ $optimized.Height }}"
|
||||||
{{- with .Get "alt" }} alt="{{ . | safeHTML }}" title="{{ . | safeHTML }}"{{ end }}></p>
|
{{- with .Get "alt" }} alt="{{ . | safeHTML }}" title="{{ . | safeHTML }}"{{ end }}></p>
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
{{- $optimized := partial "functions/optimize-image" . -}}
|
{{- $optimized := partial "functions/optimize-image" . -}}
|
||||||
|
|
||||||
<p style="text-align: center;">
|
<p style="text-align: center;">
|
||||||
<img src="{{ $optimized.Permalink }}" width="{{ .Scratch.Get "displayWidth" }}" height="{{ .Scratch.Get "displayHeight" }}"
|
<img src="{{ $optimized.Permalink }}" width="{{ $optimized.Width }}" height="{{ $optimized.Height }}"
|
||||||
{{- with .Get "alt" }} alt="{{ . | safeHTML }}" title="{{ . | safeHTML }}"{{ end }}
|
{{- with .Get "alt" }} alt="{{ . | safeHTML }}" title="{{ . | safeHTML }}"{{ end }}
|
||||||
{{- with .Inner }} alt="{{ . | markdownify | plainify | safeHTML }}" title="{{ . | markdownify | plainify | safeHTML }}"{{ end }}>
|
{{- with .Inner }} alt="{{ . | $.Page.RenderString | plainify | safeHTML }}" title="{{ . | $.Page.RenderString | plainify | safeHTML }}"{{ end }}>
|
||||||
{{ with .Inner }}<br>{{ . | $.Page.RenderString | safeHTML }}{{ end -}}
|
{{ with .Inner }}<br>{{ . | $.Page.RenderString | safeHTML }}{{ end -}}
|
||||||
</p>
|
</p>
|
||||||
|
Reference in New Issue
Block a user