我使用Jekyll作为学术网站.我使用publication类别的帖子来代表出版物.例如,美国最新总统撰写的一篇论文看起来与此类似(除了其他一些与此问题无关的变量):
---
categories: publications
layout: publication
title: "This is the paper Title"
authors: [bomama, gwbush, bclinton]
---
Run Code Online (Sandbox Code Playgroud)
特别是,我希望作者列表中的元素转换为某些预定义的URL,例如,可以将其指定为站点变量.我想这样做,所以当作者更改机构(以及他/她的网页URL)时,我不必更改每个出版物(=帖子).
谢谢!
在_config.yml你可以添加你自己的命名空间为用户定义的变量:
app:
authors:
bomama:
name: 'Barack Obama'
url: 'http://barackobama.com'
gwbush:
name: 'George W. Bush'
url: 'http://georgewbush.com'
Run Code Online (Sandbox Code Playgroud)
然后在你的模板中循环作者并合并用户定义的app:authors:
{% for id in page.authors %}
{% if site.app.authors[id] %}
<a href="{{ site.app.authors[id]['url'] }}">{{ site.app.authors[id]['name'] }}</a>
{% endif %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
输出:
<a href="http://barackobama.com">Barack Obama</a>
<a href="http://georgewbush.com">George W. Bush</a>
Run Code Online (Sandbox Code Playgroud)