Skip to content

Commit

Permalink
feat: add multiple authors to a post (#677)
Browse files Browse the repository at this point in the history
Resolves #675
  • Loading branch information
MichaelTan9999 authored Sep 13, 2022
1 parent b288587 commit f1d9e99
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
24 changes: 12 additions & 12 deletions _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,25 @@ <h1 data-toc-skip>{{ page.title }}</h1>
{% endif %}

<div class="d-flex justify-content-between">
<!-- author -->
<!-- author(s) -->
<span>
{% 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 }}

<em>
{% if author_link %}
<a href="{{ author_link }}">{{ author_name }}</a>
{% else %}
{{ author_name }}
{% endif %}
{% if authors %}
{% for author in authors %}
<a href="{{ site.data.authors[author].url }}">{{ site.data.authors[author].name }}</a>
{% unless forloop.last %}</em>, <em>{% endunless %}
{% endfor %}
{% else %}
<a href="{{ site.social.links[0] }}">{{ site.social.name }}</a>
{% endif %}
</em>
</span>

Expand Down
14 changes: 10 additions & 4 deletions _posts/2019-08-08-write-a-new-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<author_id>:
Expand All @@ -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_id>
author: <author_id> # for single entry
# or
authors: [<author1_id>, <author2_id>] # 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
Expand Down

0 comments on commit f1d9e99

Please sign in to comment.