From 85960b6fa36c93c81d060c61b0e4bafaeb6fb631 Mon Sep 17 00:00:00 2001 From: Joe Hutchinson Date: Wed, 17 Jul 2019 14:06:28 -0400 Subject: [PATCH] Update featuredImage to use page bundle approach --- archetypes/post.md | 7 +++++-- layouts/_default/li-next.html | 24 ++++++++++++------------ layouts/_default/li.html | 22 +++++++++++----------- layouts/_default/single.html | 12 ++++++------ 4 files changed, 34 insertions(+), 31 deletions(-) diff --git a/archetypes/post.md b/archetypes/post.md index 9aee58e..e05d86f 100644 --- a/archetypes/post.md +++ b/archetypes/post.md @@ -3,10 +3,13 @@ title: "{{ replace .TranslationBaseName "-" " " | title }}" date: {{ .Date }} description: "" categories: [] -featuredImage: "" -featuredImageDescription: "" dropCap: true displayInMenu: false displayInList: true draft: true +resources: +- name: featuredImage + src: "" + params: + description: "" --- diff --git a/layouts/_default/li-next.html b/layouts/_default/li-next.html index 19a8ecd..2b97804 100644 --- a/layouts/_default/li-next.html +++ b/layouts/_default/li-next.html @@ -1,17 +1,17 @@ - {{ if isset .Params "featuredimage" }} -
-

Next Article

- - {{ if (fileExists (printf "%s/%s" "static" (replace (.Params.featuredimage) (path.Ext .Params.featuredimage) ".webp"))) -}} - - {{- end }} - - - -
- {{ end }} + {{ with .Resources.GetMatch "featuredImage" }} +
+

Next Article

+ + {{ with $.Resources.GetMatch (replace (.Title) (path.Ext (.Title)) ".webp") -}} + + {{- end }} + + {{ . }} + +
+ {{ end }}

{{ .Title }}

{{ if (isset .Params "description") }}{{ index .Params "description" }}{{ else }}{{ .Summary }}{{ end }}

diff --git a/layouts/_default/li.html b/layouts/_default/li.html index e5a8dbd..6d86f42 100644 --- a/layouts/_default/li.html +++ b/layouts/_default/li.html @@ -1,16 +1,16 @@
- {{ if isset .Params "featuredimage" -}} -
- - {{ if (fileExists (printf "%s/%s" "static" (replace (.Params.featuredimage) (path.Ext .Params.featuredimage) ".webp"))) -}} - - {{- end }} - - - -
- {{- end }} + {{ with .Resources.GetMatch "featuredImage" }} +
+ + {{ with $.Resources.GetMatch (replace (.Title) (path.Ext (.Title)) ".webp") -}} + + {{- end }} + + {{ . }} + +
+ {{- end }}

{{ .Title }}

{{ if (isset .Params "description") }}{{ index .Params "description" }}{{ else }}{{ .Summary }}{{ end }}

diff --git a/layouts/_default/single.html b/layouts/_default/single.html index bd4ea3e..37307d7 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -9,13 +9,13 @@

{{ .Title }}

- {{ if isset .Params "featuredimage" }} + {{ with .Resources.GetMatch "featuredImage" }} - {{ if (fileExists (printf "%s/%s" "static" (replace (.Params.featuredimage) (path.Ext (.Params.featuredimage)) ".webp"))) -}} - - {{- end }} - - + {{ with $.Resources.GetMatch (replace (.Title) (path.Ext (.Title)) ".webp") -}} + + {{- end }} + + {{ . }} {{ end }} {{ .Content }}