support for images in page bundles as relative paths

This commit is contained in:
Gabriele Musco 2022-10-24 08:02:44 +02:00
parent bedcf7a212
commit e4a10bab22
No known key found for this signature in database
GPG key ID: 1068D795C80E51DE
7 changed files with 55 additions and 11 deletions

View file

@ -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 }}
}