From c5ac01dd2880ee699734402ae58d62929bd1954d Mon Sep 17 00:00:00 2001 From: liushuyu Date: Sat, 31 Oct 2020 16:42:08 -0600 Subject: [PATCH] layout/entry/single: add support for multiple coauthors --- layouts/entry/single.html | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/layouts/entry/single.html b/layouts/entry/single.html index 8d8df31..6212373 100644 --- a/layouts/entry/single.html +++ b/layouts/entry/single.html @@ -1,25 +1,41 @@ {{ define "header" }} {{ $author := index .Site.Data.authors ( .Params.author | default "" ) }} -{{ $coauthor := index .Site.Data.authors ( .Params.coauthor | default "" ) }} +{{ $coauthors := split ( .Params.coauthor | default "" ) "," }}
{{ .Title }}
- {{ if and $author $coauthor }} + {{ if and $author $coauthors }}
- - Written by {{ $author.name }} - and {{ $coauthor.name }} +

+ Written by {{ $author.name }} + {{/* if len($coauthors) < 2 */}} + {{ if lt (len $coauthors) 2 }} + {{ $coauthor := index .Site.Data.authors ( .Params.coauthor | default "" ) }} + and {{ $coauthor.name }} + {{ else }} + in collaboration with + {{ $length := len $coauthors }} + {{ range $i, $name := $coauthors }} + {{ $coauthor := index $.Site.Data.authors $name }} + {{/* if i == length -1 */}} + {{ if eq $i (sub $length 1) }} + and + {{ end }} + {{ $coauthor.name }}{{- if lt $i (sub $length 1) -}},{{- end -}} + {{/* if i < length - 1 */}} + {{ end }} + {{ end }} on {{ .Date.Format $.Site.Params.fmt.Date }} - +

{{ else if $author }}
- Written by {{ $author.name }} + Written by {{ $author.name }} on {{ .Date.Format $.Site.Params.fmt.Date }} - +
{{ else }}