From e4a10bab2283838575745dd037c1202e51cd9170 Mon Sep 17 00:00:00 2001 From: Gabriele Musco Date: Mon, 24 Oct 2022 08:02:44 +0200 Subject: [PATCH] support for images in page bundles as relative paths --- layouts/_default/search.json | 10 +++++++++- layouts/index.json | 10 +++++++++- layouts/partials/article_card.html | 6 +++++- layouts/partials/featured_articles.html | 10 +++++++++- layouts/partials/head_meta_opengraph.html | 12 +++++++++--- layouts/partials/head_meta_twitter.html | 12 +++++++++--- layouts/partials/single_post.html | 6 +++++- 7 files changed, 55 insertions(+), 11 deletions(-) diff --git a/layouts/_default/search.json b/layouts/_default/search.json index f740da8..b374521 100644 --- a/layouts/_default/search.json +++ b/layouts/_default/search.json @@ -4,6 +4,14 @@ {{ $mscratch.Add "articles" slice }} {{ $pages := where .Site.RegularPages "Params.nosearch" "!=" "true" }} {{ range $pages }} + {{ $image := "" }} + {{ if .Params.Image }} + {{ if or (hasPrefix .Params.Image "/") (hasPrefix .Params.Image "http://") (hasPrefix .Params.Image "https://") }} + {{ $image = .Params.Image }} + {{ else }} + {{ $image = path.Join "/" (path.Join .File.Dir .Params.Image) }} + {{ end }} + {{ end }} {{ $mscratch.Add "articles" (dict "title" .Title "date" (.Date.Format "2006-01-02") @@ -11,7 +19,7 @@ "summary" (or .Params.description .Summary) "text" (lower .Plain) "link" .Permalink - "image" (or .Params.Image "")) }} + "image" $image) }} {{ end }} "pages": {{ $mscratch.Get "articles" | jsonify }} } diff --git a/layouts/index.json b/layouts/index.json index 4259ba0..1d17dd4 100644 --- a/layouts/index.json +++ b/layouts/index.json @@ -11,13 +11,21 @@ {{ $mscratch := newScratch }} {{ $mscratch.Add "articles" slice }} {{ range (.Paginate $postsList).Pages }} + {{ $image := "" }} + {{ if .Params.Image }} + {{ if or (hasPrefix .Params.Image "/") (hasPrefix .Params.Image "http://") (hasPrefix .Params.Image "https://") }} + {{ $image = .Params.Image }} + {{ else }} + {{ $image = path.Join (path.Join .File.Dir .Params.Image) }} + {{ end }} + {{ end }} {{ $mscratch.Add "articles" (dict "title" .Title "date" (.Date.Format "2006-01-02") "tags" (sort (or .Params.tags slice)) "summary" (or .Params.description .Summary) "link" .Permalink - "image" (or .Params.Image "")) }} + "image" $image) }} {{ end }} "articles": {{ $mscratch.Get "articles" | jsonify }}, "test": "{{range $postsList}}{{.Title}} {{end}}", diff --git a/layouts/partials/article_card.html b/layouts/partials/article_card.html index 6a8c7ad..62c11bf 100644 --- a/layouts/partials/article_card.html +++ b/layouts/partials/article_card.html @@ -17,7 +17,11 @@ {{ if .Site.Params.imageInArticlePreview }} {{ if .Params.Image }} - + {{ if or (hasPrefix .Params.Image "/") (hasPrefix .Params.Image "http://") (hasPrefix .Params.Image "https://") }} + + {{ else }} + + {{ end }} {{ end }} {{end}} diff --git a/layouts/partials/featured_articles.html b/layouts/partials/featured_articles.html index 4dfdf2d..4ff6a8f 100644 --- a/layouts/partials/featured_articles.html +++ b/layouts/partials/featured_articles.html @@ -1,5 +1,13 @@