From f1d9e99bc02d3cd0a6b0cd1beac545f0cc7a24f8 Mon Sep 17 00:00:00 2001
From: Michael Tan <20365364+MichaelTan9999@users.noreply.github.com>
Date: Wed, 14 Sep 2022 05:05:01 +0800
Subject: [PATCH] feat: add multiple authors to a post (#677)
Resolves #675
---
_layouts/post.html | 24 ++++++++++++------------
_posts/2019-08-08-write-a-new-post.md | 14 ++++++++++----
2 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/_layouts/post.html b/_layouts/post.html
index 255832c..e3d922c 100644
--- a/_layouts/post.html
+++ b/_layouts/post.html
@@ -57,25 +57,25 @@ tail_includes:
{% endif %}
-
+
- {% capture author_name %}{{ site.data.authors[page.author].name | default: site.social.name }}{% endcapture %}
- {% assign author_link = nil %}
-
{% if page.author %}
- {% assign author_link = site.data.authors[page.author].url %}
- {% elsif author_name == site.social.name %}
- {% assign author_link = site.social.links[0] %}
+ {% assign authors = page.author %}
+ {% elsif page.authors %}
+ {% assign authors = page.authors %}
{% endif %}
{{ site.data.locales[lang].post.written_by }}
- {% if author_link %}
- {{ author_name }}
- {% else %}
- {{ author_name }}
- {% endif %}
+ {% if authors %}
+ {% for author in authors %}
+ {{ site.data.authors[author].name }}
+ {% unless forloop.last %}, {% endunless %}
+ {% endfor %}
+ {% else %}
+ {{ site.social.name }}
+ {% endif %}
diff --git a/_posts/2019-08-08-write-a-new-post.md b/_posts/2019-08-08-write-a-new-post.md
index d40c3eb..acea436 100644
--- a/_posts/2019-08-08-write-a-new-post.md
+++ b/_posts/2019-08-08-write-a-new-post.md
@@ -48,7 +48,7 @@ tags: [bee]
The author information of the post usually does not need to be filled in the _Front Matter_ , they will be obtained from variables `social.name` and the first entry of `social.links` of the configuration file by default. But you can also override it as follows:
-Add author information in `_data/authors.yml` (If your website doesn't have this file, don't hesitate to create one.)
+Adding author information in `_data/authors.yml` (If your website doesn't have this file, don't hesitate to create one).
```yaml
:
@@ -58,15 +58,21 @@ Add author information in `_data/authors.yml` (If your website doesn't have this
```
{: file="_data/authors.yml" }
-And then set up the custom author in the post's YAML block:
+
+And then use `author` to specify a single entry or `authors` to specify multiple entries:
```yaml
---
-author:
+author: # for single entry
+# or
+authors: [, ] # for multiple entries
---
```
-> Another benefit of reading the author information from the file `_data/authors.yml`{: .filepath } is that the page will have the meta tag `twitter:creator`, which enriches the [Twitter Cards](https://developer.twitter.com/en/docs/twitter-for-websites/cards/guides/getting-started#card-and-content-attribution) and is good for SEO.
+
+Having said that, the key `author` can also identify multiple entries.
+
+> The benefit of reading the author information from the file `_data/authors.yml`{: .filepath } is that the page will have the meta tag `twitter:creator`, which enriches the [Twitter Cards](https://developer.twitter.com/en/docs/twitter-for-websites/cards/guides/getting-started#card-and-content-attribution) and is good for SEO.
{: .prompt-info }
## Table of Contents