layout/entry/single: add support for multiple coauthors

This commit is contained in:
liushuyu 2020-10-31 16:42:08 -06:00
parent 5a87667766
commit c5ac01dd28
No known key found for this signature in database
GPG key ID: 23D1CE4534419437

View file

@ -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 "" ) "," }}
<div class="mb-md blog-entry-header single" style="background-image: url('{{ .Site.BaseURL }}/{{ .Dir }}banner.png')"></div>
<div class="has-text-centered">
<div>
<span class="title px-md py-sm">{{ .Title }}</span>
</div>
{{ if and $author $coauthor }}
{{ if and $author $coauthors }}
<div>
<span class="h3 px-md py-sm">
Written by <a href="https://community.citra-emu.org/users/{{ $author.key }}">{{ $author.name }}</a>
and <a href="https://community.citra-emu.org/users/{{ $coauthor.key }}">{{ $coauthor.name }}</a>
<p class="h3 px-md py-sm">
Written by <a href="https://community.citra-emu.org/users/{{ $author.key }}">{{ $author.name }}</a>
{{/* if len($coauthors) < 2 */}}
{{ if lt (len $coauthors) 2 }}
{{ $coauthor := index .Site.Data.authors ( .Params.coauthor | default "" ) }}
and <a href="https://community.citra-emu.org/users/{{ $coauthor.key }}">{{ $coauthor.name }}</a>
{{ 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 }}
<a href="https://community.citra-emu.org/users/{{ $coauthor.key }}">{{ $coauthor.name }}</a>{{- if lt $i (sub $length 1) -}},{{- end -}}
{{/* if i < length - 1 */}}
{{ end }}
{{ end }}
on {{ .Date.Format $.Site.Params.fmt.Date }}
</span>
</p>
</div>
{{ else if $author }}
<div>
<span class="h3 px-md py-sm">
Written by <a href="https://community.citra-emu.org/users/{{ $author.key }}">{{ $author.name }}</a>
Written by <a href="https://community.citra-emu.org/users/{{ $author.key }}">{{ $author.name }}</a>
on {{ .Date.Format $.Site.Params.fmt.Date }}
</span>
</span>
</div>
{{ else }}
<div>