feat: avoid regenerate color scheme when image URL is changed

Use MD5 as key to identify images, and .Slug as id
This commit is contained in:
Jimmy Cai
2020-08-28 12:11:02 +02:00
parent ced9823d99
commit 32732d4bf1
5 changed files with 30 additions and 21 deletions
+2 -2
View File
@@ -20,10 +20,10 @@
<header class="article-category">
{{ range $categories }}
{{ if $i }}
{{- $image := partial "helper/image" $context -}}
{{- $image := partial "helper/image" $context | resources.Fingerprint "md5" -}}
{{- $20x := $image.Fill "20x20 smart" -}}
<a href="/categories/{{ . | urlize }}" class="color-tag"
data-image="{{ $20x.RelPermalink }}">{{ . | humanize }}</a>
data-image="{{ $20x.RelPermalink }}" data-id="{{ $context.Slug }}" data-key="{{ $image.Data.Integrity }}">{{ . | humanize }}</a>
{{ else }}
<a href="/categories/{{ . | urlize }}">{{ . | humanize }}</a>
{{ end }}
+3 -2
View File
@@ -1,10 +1,11 @@
<article class="{{ if .context.Params.image }}has-image{{ end }}">
<a href="{{ .context.Permalink }}">
{{ if .context.Params.image }}
{{- $thumbnail := (partial "helper/image" (.context) ).Fill .size -}}
{{- $image := partial "helper/image" .context | resources.Fingerprint "md5" -}}
{{- $thumbnail := $image.Fill .size -}}
<div class="article-image">
<img src="{{ $thumbnail.RelPermalink }}" width="{{ $thumbnail.Width }}" height="{{ $thumbnail.Height }}"
loading="lazy">
loading="lazy" data-id="{{ .context.Slug }}" data-key="{{ $image.Data.Integrity }}">
</div>
{{ end }}
@@ -5,9 +5,6 @@
{{- $tablet := $image.Resize "1024x" -}}
{{- $desktop := $image.Resize "2000x" -}}
{{- $20x := $image.Fill "20x20 smart" -}}
{{- .Scratch.Set "20x" $20x -}}
<div class="article-image">
<img srcset="{{ $tablet.RelPermalink }} 1024w, {{ $desktop.RelPermalink }} 2000w"
src="{{ $desktop.RelPermalink }}" width="{{ $image.Width }}" height="{{ $image.Height }}"
@@ -16,13 +13,17 @@
</div>
{{ end }}
{{ $i := .Params.image }}
{{ $context := . }}
<div class="article-details">
{{ with $category := .Params.categories }}
{{ with $categories := .Params.categories }}
<header class="article-category">
{{ range $category }}
{{ if $.Params.image }}
{{ range $categories }}
{{ if $i }}
{{- $image := partial "helper/image" $context | resources.Fingerprint "md5" -}}
{{- $20x := $image.Fill "20x20 smart" -}}
<a href="/categories/{{ . | urlize }}" class="color-tag"
data-image="{{ ($.Scratch.Get "20x").RelPermalink }}">{{ . | humanize }}</a>
data-image="{{ $20x.RelPermalink }}" data-id="{{ $context.Slug }}" data-key="{{ $image.Data.Integrity }}">{{ . | humanize }}</a>
{{ else }}
<a href="/categories/{{ . | urlize }}">{{ . | humanize }}</a>
{{ end }}