From 525ba3c1d2009af50ab65ce9ff963085fdf02dbc Mon Sep 17 00:00:00 2001 From: James Elliott Date: Wed, 23 Mar 2022 22:14:30 +1100 Subject: [PATCH] fix(layouts): use comma for more than 2 contributors This makes the byline show commas on all but the last author of a blog post. --- layouts/partials/main/blog-meta.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/layouts/partials/main/blog-meta.html b/layouts/partials/main/blog-meta.html index a9eb438..d3cc3b7 100644 --- a/layouts/partials/main/blog-meta.html +++ b/layouts/partials/main/blog-meta.html @@ -1 +1,2 @@ -

Posted {{ .PublishDate.Format "January 2, 2006" }} by {{ if .Params.contributors -}}{{ range $index, $contributor := .Params.contributors }}{{ if gt $index 0 }} and {{ end }}{{ . }}{{ end -}}{{ end -}} ‐ {{ .ReadingTime -}} min read

\ No newline at end of file +{{ $last := sub (len .Params.contributors) 1 }} +

Posted {{ .PublishDate.Format "January 2, 2006" }} by {{ if .Params.contributors -}}{{ range $index, $contributor := .Params.contributors }}{{ if gt $index 0 }}{{ if eq $index $last }} and {{ else }}, {{ end }}{{ end }}{{ . }}{{ end -}}{{ end -}} ‐ {{ .ReadingTime -}} min read