diff --git a/README.md b/README.md index 31c3ef4..e0e7060 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/pelican_cite.py b/pelican_cite.py index b35e2b8..2572896 100644 --- a/pelican_cite.py +++ b/pelican_cite.py @@ -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 @@ -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("@","@") @@ -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) @@ -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: