跳转到主要内容

Biblary是一个基于bibtex库的提供参考文献的Django应用程序。

项目描述

Biblary

安装

推荐的安装方法是使用pip

pip install biblary

开始使用

首先,确保应用程序已添加到您的项目设置中的INSTALLED_APPS

# settings.py
INSTALLED_APPS = (
    ...
    'biblary',
)

接下来,将URL添加到您的项目中

# urls.py
from django.urls import path, include

urlpatterns = [
    path('biblary/', include('biblary.urls', namespace='biblary')),
]

最后,需要配置参考文献后端适配器。例如,要服务包含BibTeX条目的文件的内容,请使用BibtexBibliography适配器

# settings.py
import pathlib

BIBLARY_BIBLIOGRAPHY_ADAPTER = 'biblary.bibliography.adapter.bibtex.BibtexBibliography'
BIBLARY_BIBLIOGRAPHY_ADAPTER_CONFIGURATION = {
    'filepath': pathlib.Path('/some/path/to/bibliography.bib')
}

filepath是配置的唯一必需键,应是一个指向BibTeX文件的pathlib.Path对象。

可用的适配器

BibtexBibliography

此适配器旨在服务包含BibTeX条目的文件的内容。

配置参数

  • filepath:指向包含参考文献条目的BibTeX文件的pathlib.Path对象。

编写自定义适配器

要提供一个自定义参考文献后端适配器,应实现biblary.bibliography.adapter.abstract.BibliographyAdapter

# -*- coding: utf-8 -*-
import typing as t

from biblary.bibliography.adapter import BibliographyAdapter
from biblary.bibliography.entry import BibliographyEntry


class CustomBibliographyAdapter(BibliographyAdapter):
    """Implementation of a ``BibliographyAdapter``."""

    def __init__(self, *args, **kwargs):
        """Construct a new instance and configure the adapter."""
        super().__init__(*args, **kwargs)

    def get_entries(self) -> t.List[BibliographyEntry]:
        """Return the list of bibliography entries."""

构造函数应定义它应接受哪些关键字参数来配置适配器。为 BIBLARY_BIBLIOGRAPHY_ADAPTER_CONFIGURATION 指定的关键字参数将在加载参考文献时传递给适配器的构造函数。最后,应实现 get_entries 方法。该方法应返回一个包含 biblary.bibliography.entry.BiliographyEntry 实例的列表,每个实例对应参考文献中的一个条目。

配置

BIBLARY_BIBLIOGRAPHY_MAIN_AUTHOR_PATTERNS

此设置接受一个正则表达式模式元组,例如

BIBLARY_BIBLIOGRAPHY_MAIN_AUTHOR_PATTERNS = ('Paul Dirac', r'.*Dirac')

模板标签 main_author_class 将使用此设置来确定传递给它的作者是否被视为主要作者。如果是这种情况,将返回由 BIBLARY_BIBLIOGRAPHY_MAIN_AUTHOR_CLASS 设置定义的字符串。这可以在 index 模板中如下使用

{% for entry in entries %}
<div class="biblary-entry-authors">
    {% for author in entry.author %}
    <span class="biblary-entry-author {% main_author_class author %}">{{ author }}</span>
    {% endfor %}
</div>
{% endfor %}

任何与设置中指定的任何模式匹配的作者都将获得额外的类。

BIBLARY_BIBLIOGRAPHY_MAIN_AUTHOR_CLASS

当指定的作者与 BIBLARY_BIBLIOGRAPHY_MAIN_AUTHOR_PATTERNS 设置中定义的任何模式匹配时,由 main_author_class 标签返回。默认为 biblary-entry-author-main

项目详情


下载文件

下载适用于您的平台文件。如果您不确定要选择哪个,请了解更多关于 安装包 的信息。

源分发

biblary-0.2.0.tar.gz (15.1 kB 查看哈希值)

上传时间

构建分发

biblary-0.2.0-py3-none-any.whl (20.4 kB 查看哈希值)

上传时间 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面