Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple bib files support #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ information within your articles and pages.
Configuration is simply:

```python
PUBLICATIONS_SRC = 'content/pubs.bib'
PUBLICATIONS_SRC = ['content/pubs.bib', 'content/pub2.bib']
```

If the file is present and readable, then content will be scanned for references
If the files are present and readable, then content will be scanned for references
to citation keys. These take the format `[@Bai2011]` or `[@@Bai2011]`. These
will be replaced by incline citations which provide links to the full
bibliographic information at the end of the article. The former reference would
Expand Down
39 changes: 21 additions & 18 deletions pelican_cite.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,16 @@ def get_bib_file(article):
it and return the parsed object.
"""
if 'publications_src' in article.metadata:
refs_file = article.metadata['publications_src']
try:
local_bib = Parser().parse_file(refs_file)
refs_files = article.metadata['publications_src']
local_bib = []
for refs_file in refs_files:
try:
local_bib.append(Parser().parse_file(refs_file) )
except PybtexError as e:
logger.warn('`pelican_bibtex` failed to parse file %s: %s' % (refs_file, str(e)))
if len(local_bib) > 0:
return local_bib
except PybtexError as e:
logger.warn('`pelican_bibtex` failed to parse file %s: %s' % (
refs_file,
str(e)))
else:
return global_bib
else:
return global_bib
Expand All @@ -85,8 +87,8 @@ def process_content(article):
Substitute the citations and add a bibliography for an article or
page, using the local bib file if specified or the global one otherwise.
"""
data = get_bib_file(article)
if not data:
bib_files = get_bib_file(article)
if not bib_files:
return
content = article._content
content = content.replace("@","@")
Expand All @@ -103,8 +105,9 @@ def process_content(article):

# Get formatted entries for the appropriate bibliographic entries
cited = []
for key in data.entries.keys():
if key in cite_count: cited.append(data.entries[key])
for data in bib_files:
for key in data.entries.keys():
if key in cite_count: cited.append(data.entries[key])
if len(cited) == 0: return
formatted_entries = style.format_entries(cited)

Expand Down Expand Up @@ -165,13 +168,13 @@ def add_citations(generators):
return

if 'PUBLICATIONS_SRC' in generators[0].settings:
refs_file = generators[0].settings['PUBLICATIONS_SRC']
try:
global_bib = Parser().parse_file(refs_file)
except PybtexError as e:
logger.warn('`pelican_bibtex` failed to parse file %s: %s' % (
refs_file,
str(e)))
refs_files = generators[0].settings['PUBLICATIONS_SRC']
global_bib = []
for refs_file in refs_files:
try:
global_bib.append(Parser().parse_file(refs_file) )
except PybtexError as e:
logger.warn('`pelican_bibtex` failed to parse file %s: %s' % (refs_file, str(e)))

# Process the articles and pages
for generator in generators:
Expand Down