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,18 +1,34 @@
{{ define "header" }} {{ define "header" }}
{{ $author := index .Site.Data.authors ( .Params.author | default "" ) }} {{ $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="mb-md blog-entry-header single" style="background-image: url('{{ .Site.BaseURL }}/{{ .Dir }}banner.png')"></div>
<div class="has-text-centered"> <div class="has-text-centered">
<div> <div>
<span class="title px-md py-sm">{{ .Title }}</span> <span class="title px-md py-sm">{{ .Title }}</span>
</div> </div>
{{ if and $author $coauthor }} {{ if and $author $coauthors }}
<div> <div>
<span class="h3 px-md py-sm"> <p 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>
{{/* 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> 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 }} on {{ .Date.Format $.Site.Params.fmt.Date }}
</span> </p>
</div> </div>
{{ else if $author }} {{ else if $author }}
<div> <div>