如何在Jekyll中为一篇文章安排多位作者? [英] How can I have multiple authors for one post in Jekyll?

查看:59
本文介绍了如何在Jekyll中为一篇文章安排多位作者?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在jekyll帖子上有以下标头,其中包含一个作者"usman",该作者生成了

I have the following header on a jekyll post with a single author "usman" which generates the this article. I would like to have something like "authors: usman, someone_else" so a colleague can also contribute to the article. Is this possible? How would I set it up.

--- 
layout: post
title: The pitfalls of building services using Google App Engine -- Part I
date: 2013-02-24 08:18:17
author: usman
categories: 
- System Admin
tags:
- GAE

---

我看了我正在使用的主题的帖子模板,它包含以下行:

I took a look at the post template for the theme I am using and it has the following line:

{% assign author = site.authors[page.author] %}

这显然仅支持一位作者,有没有办法让该页面的两位作者呢?例如page.author [0]?

This will obviously only support one author, Is there a way to get both authors of the page? i.e. page.author[0] for example?

推荐答案

如果您想在YAML Frontmatter中指定多个作者,那么您将想像使用类别和标记一样使用YAML的列表语法,就像这样:

If you want to specify multiple authors in your YAML Frontmatter, then you are going to want to use YAML's list syntax like you did with categories and tags, like this:

author:
- usman
- someone_else

这对于在每个帖子中动态注入作者信息很有用.

This will be useful for dynamically injecting author information into each of the posts.

关于允许多个人对同一篇文章做出贡献,我认为这与Jekyll或Frontmatter中指定的内容无关.这是将您的Jekyll内容托管在一个共享的地方(例如,像很多人一样在GitHub上)托管的问题,您和您的协作者都可以在该地方工作该文件.话虽这么说,但是请注意,如果并行处理同一markdown文件,则可能会遇到讨厌的合并冲突.

As for allowing multiple people to contribute to the same article, I don't think this has anything to do with Jekyll or what is specified in the Frontmatter. This is an issue of having your Jekyll content hosted in a shared place (such as on GitHub, like many do) where both you and your collaborator can both work on the file. That being said, be aware that you may run into nasty merge conflicts if you work on that same markdown file in parallel.

更新

这是基于OP对原始问题的编辑而进行的更新.

This is an update based on the OP's edits to the original question.

一种简单的黑客手段是像这样设置您的作者标签:

A simple hacked approach would be to set your author tag like this:

author: Usman and Someone_Else

这并不能给您带来很大的灵活性.更好的解决方案将要求您修改正在使用的模板,方法是执行以下操作:

This doesn't give you much flexibility though. A better solution, which would require you to modify the template you are using, would be to do something like the following:

首先,设置您的YAML前端事务,以便它可以支持多位作者.

First, setup your YAML Front Matter so that it can support multiple authors.

authors:
- Usman
- Someone_else

现在,您修改模板以遍历YAML前沿事项中指定的作者.

Now, you modify the template to go through the authors specified in the YAML Front Matter.

<p>
{% assign authorCount = page.authors | size %}
{% if authorCount == 0 %}
    No author
{% elsif authorCount == 1 %}
    {{ page.authors | first }}
{% else %}
    {% for author in page.authors %}
        {% if forloop.first %}
            {{ author }}
        {% elsif forloop.last %}
            and {{ author }}
        {% else %}
            , {{ author }}
        {% endif %}
    {% endfor %}
{% endif %}
</p>

结果HTML:

如果未指定作者:

<p>No author</p>

如果指定了一位作者:

<p>Usman</p>

如果指定了两位作者:

<p>Usman and Someone_Else</p>

如果指定了两个以上的作者:

If more than two authors are specified:

<p>Usman, Bob, and Someone_Else</p>

这篇关于如何在Jekyll中为一篇文章安排多位作者?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆