使用鹈鹕和bibtex组织科学出版物
pelican-bib的Python项目详细描述
鹈鹕围兜
在鹈鹕用bibtex组织你的科学出版物。这个包基于vlad的pelican-bibtex。当前版本向后兼容,可以替换当前项目的pelican-bibtex
安装。
安装
pelican_bib
需要pybtex
。
pip install pybtex
使用pip
pip install pelican-bib
将插件添加到PLUGINS
变量:
PLUGINS = ['pelican_bib', ...]
作为子模块
在您的鹈鹕网站:
$ mkdir plugins
$ git submodule add https://github.com/scheunemann/pelican-bib plugins/pelican-bib
鹈鹕形态:
PLUGIN_PATHS = ['plugins/pelican_bib', ...]
PLUGINS = ['pelican_bib', ...]
如何使用
此插件读取用户指定的bibtex文件并用 一个出版物列表,可以在Jinja2模板中使用。
配置很简单:
PUBLICATIONS_SRC = 'content/pubs.bib'
如果文件存在且可读,您将能够找到publications
所有模板中的变量。这是一个字典列表,包含以下键:
key
是条目的bibtex键(标识符)。year
是条目发布的年份。对于使用jinja的groupby
在模板中按年分组很有用text
是html格式的条目,由pybtex
生成。bibtex
是一个字符串,包含该项的bibtex代码,使其成为 提供给那些想引用你作品的人。pdf
,slides
,poster
:在bibtex文件中,可以添加这些特殊字段, 例如:@article{ foo13 ... pdf = {/papers/foo13.pdf}, slides = {/slides/foo13.html} }
此插件将获取所有定义的字段,并使它们在模板中可用。
如果没有定义字段,元组字段将是None
。而且,
字段从生成的bibtex中剥离(在bibtex
字段中找到)。
分成出版物列表
您可以为每个bibtex条目添加一个额外字段。该字段的值是一个逗号分隔的列表。
这些值将成为包含模板中相关联的bibtex项的列表publications_lists
的键。
例如,如果要将一个条目与两个不同的标记关联(foo-tag
,bar-tag
),
将以下字段添加到bib条目:
@article{
foo13
...
tags = {foo-tag, bar-tag}
}
在您的pelicanconf.py
中,您需要设置:
PUBLICATIONS_SPLIT_BY = 'tags'
在模板中,您可以使用变量publications_lists['foo-tag']
和publications_lists['bar-tag']
访问这些列表。
如果要分配所有未标记的条目(即没有标记的条目
在PUBLICATIONS_SPLIT_BY
)中定义到名为others
的标记的字段,设置:
PUBLICATIONS_UNTAGGED_TITLE = 'others'
带有出版物列表的页面
要使用以下方法之一生成显示出版物的页面,需要添加模板文件和页面。
1.)将模板文件作为publications.html
放在content/templates
中,并将其作为直接模板添加到网页中。添加您的pelicanconf.py
:
THEME_TEMPLATES_OVERRIDES.append('templates')
2.)在页面文件夹中创建一个页面,例如“content/pages/publications.rst”,内容中包含以下元数据:
Publications
############
:template: publications
示例模板
publications.html
模板的示例内容:
{% extends "base.html" %}
{% block title %}Publications{% endblock %}
{% block content %}
<script type="text/javascript">
function disp(s) {
var win;
var doc;
win = window.open("", "WINDOWID");
doc = win.document;
doc.open("text/plain");
doc.write("<pre>" + s + "</pre>");
doc.close();
}
</script>
<section id="content" class="body">
<h1 class="entry-title">Publications</h1>
<ul>
{% for publication in publications %}
<li id="{{ publication.key }}">{{ publication.text }}
[ <a href="javascript:disp('{{ publication.bibtex|replace('\n', '\\n')|escape|forceescape }}');">Bibtex</a> ]
{% for label, target in [('PDF', publication.pdf), ('Slides', publication.slides), ('Poster', publication.poster)] %}
{{ "[ <a href=\"%s\">%s</a> ]" % (target, label) if target }}
{% endfor %}
</li>
{% endfor %}
</ul>
</section>
{% endblock %}
(注意:为了正确显示bibtex字符串,我们将对其进行两次转义。
这可以通过forceescape
排序条目
条目可以按其中一个属性排序,例如,如果要按日期排序条目,则无序列表将如下所示:
...
<ul>
{% for publication in publications|sort(True, attribute='year') %}
<li id="{{ publication.key }}">{{ publication.text }}
[ <a href="javascript:disp('{{ publication.bibtex|replace('\n', '\\n')|escape|forceescape }}');">Bibtex</a> ]
{% for label, target in [('PDF', publication.pdf), ('Slides', publication.slides), ('Poster', publication.poster)] %}
{{ "[ <a href=\"%s\">%s</a> ]" % (target, label) if target }}
{% endfor %}
</li>
{% endfor %}
</ul>
...
在Jinja2的2.6版中添加了sort builtin filter。
分组条目
要按年份对条目进行分组,
...
<ul>
{% for grouper, publist in publications|groupby('year')|reverse %}
<li> {{grouper}}
<ul>
{% for publication in publist %}
<li id="{{ publication.key }}">{{ publication.text }}
[ <a href="javascript:disp('{{ publication.bibtex|replace('\n', '\\n')|escape|forceescape }}');">Bibtex</a> ]
{% for label, target in [('PDF', publication.pdf), ('Slides', publication.slides), ('Poster', publication.poster)] %}
{{ "[ <a href=\"%s\">%s</a> ]" % (target, label) if target }}
{% endfor %}
</li>
{% endfor %}
</ul></li>
{% endfor %}
</ul>
...
使用出版物列表
如上所述,出版物列表存储在publications_lists
中。
您可以用publications_lists['foo-tag']
替换前面示例中的publications
,以仅显示带有foo-tag
标记的发布。
您还可以遍历映射并显示每个列表的所有bib条目。 上一示例的部分更改为:
...
<section id="content" class="body">
<h1 class="entry-title">Publications</h1>
{% for tag in publications_lists %}
{% if publications_lists|length > 1 %}
<h2>{{tag}}</h2>
{% endif %}
<ul>
{% for publication in publications_lists[tag] %}
<li id="{{ publication.bibkey }}">{{ publication.text }}
[ <a href="javascript:disp('{{ publication.bibtex|replace('\n', '\\n')|escape|forceescape }}');">Bibtex</a> ]
{% for label, target in [('PDF', publication.pdf), ('Slides', publication.slides), ('Poster', publication.poster)] %}
{{ "[ <a href=\"%s\">%s</a> ]" % (target, label) if target }}
{% endfor %}
</li>
{% endfor %}
</ul>
{% endfor %}
</section>
...