Skip to content

Commit 99da1e2

Browse files
FilipFilip
authored andcommitted
feat: add global bibliography support to pandoc-reader plugin
- Add support for global bibliography files with configurable names - Maintain backward compatibility with individual bibliography files - Add PANDOC_GLOBAL_BIB_FILES setting - Add comprehensive tests for all scenarios - Update documentation and provide example configuration
1 parent 898fbfd commit 99da1e2

13 files changed

Lines changed: 309 additions & 4 deletions

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,31 @@ Without these settings, citations will not be processed by the plugin.
181181

182182
It is not necessary to specify the `+citations` extension since it is enabled by default. However, if you were to disable citations by specifying `-citations` in `PANDOC_EXTENSIONS` or by setting `reader: markdown-citations` in your defaults file, citations will **not** work.
183183

184-
You may write your bibliography in any format supported by Pandoc with the appropriate extensions specified. However, you **must** name the bibliography file the same as your post.
184+
You may write your bibliography in any format supported by Pandoc with the appropriate extensions specified. The plugin supports both individual and global bibliography files.
185185

186-
For example, a post with the file name `my-post.md` should have a bibliography file called `my-post.bib`, `my-post.json`, `my-post.yaml` or `my-post.bibtex` in the same directory as your post, or in a subdirectory of the directory that your blog resides in. Failure to do so will prevent the references from being picked up.
186+
#### Individual Bibliography Files
187+
188+
By default, the plugin looks for bibliography files that have the same name as your post. For example, a post with the file name `my-post.md` should have a bibliography file called `my-post.bib`, `my-post.json`, `my-post.yaml` or `my-post.bibtex` in the same directory as your post, or in a subdirectory of the directory that your blog resides in.
189+
190+
#### Global Bibliography Files
191+
192+
You can also use global bibliography files that contain references for multiple articles. The plugin will automatically search for global bibliography files with the following default names:
193+
194+
* `_bibliography.bib`, `_bibliography.json`, `_bibliography.yaml`, `_bibliography.bibtex`
195+
* `bibliography.bib`, `bibliography.json`, `bibliography.yaml`, `bibliography.bibtex`
196+
* `references.bib`, `references.json`, `references.yaml`, `references.bibtex`
197+
198+
To customize the global bibliography file names, set the `PANDOC_GLOBAL_BIB_FILES` setting in your Pelican settings file:
199+
200+
```python
201+
PANDOC_GLOBAL_BIB_FILES = ["my_bib", "global_refs", "shared_bibliography"]
202+
```
203+
204+
This will make the plugin search for files like `my_bib.bib`, `global_refs.bib`, etc.
205+
206+
#### Bibliography File Priority
207+
208+
The plugin searches for both individual and global bibliography files. If both types exist, all found bibliography files will be used by Pandoc. The order in which they are processed follows the order they are discovered during the recursive directory search.
187209

188210
#### Known Issues with Citations
189211

pelican/plugins/pandoc_reader/pandoc_reader.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,17 +390,28 @@ def _check_if_toc(arguments):
390390
table_of_contents = True
391391
return table_of_contents
392392

393-
@staticmethod
394-
def _find_bibs(source_path):
393+
def _find_bibs(self, source_path):
395394
"""Find bibliographies recursively in the sourcepath given."""
396395
bib_files = []
397396
filename = os.path.splitext(os.path.basename(source_path))[0]
398397
directory_path = os.path.dirname(os.path.abspath(source_path))
398+
399+
global_bib_names = self.settings.get(
400+
"PANDOC_GLOBAL_BIB_FILES",
401+
["_bibliography", "bibliography", "references"]
402+
)
403+
399404
for root, _, files in os.walk(directory_path):
400405
for extension in VALID_BIB_EXTENSIONS:
401406
bib_name = ".".join([filename, extension])
402407
if bib_name in files:
403408
bib_files.append(os.path.join(root, bib_name))
409+
410+
for global_name in global_bib_names:
411+
global_bib_name = ".".join([global_name, extension])
412+
if global_bib_name in files:
413+
bib_files.append(os.path.join(root, global_bib_name))
414+
404415
return bib_files
405416

406417
@staticmethod
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@online{mann2019,
2+
url = {https://www.livescience.com/65033-what-is-string-theory.html},
3+
title = {{What Is String Theory?}},
4+
author = {Adam Mann},
5+
date = {2019-03-20},
6+
urldate = {2020-11-12}
7+
}
8+
9+
@online{wood2019,
10+
url = {https://www.space.com/17594-string-theory.html},
11+
title = {{What Is String Theory?}},
12+
titleaddon = {Reference Article: A simplified explanation and brief history of string theory},
13+
author = {Charlie Wood},
14+
date = {2019-07-11},
15+
urldate = {2020-11-12}
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@online{francis2019,
2+
url = {https://www.scientificamerican.com/article/is-string-theory-science/},
3+
title = {{Falsifiability and physics}},
4+
titleaddon = {Can a theory that isn't completely testable still be useful to physics?},
5+
author = {Matthew R Francis},
6+
date = {2019-04-23},
7+
urldate = {2020-11-12}
8+
}
9+
10+
@online{alves2017,
11+
url = {https://metafact.io/factchecks/30-is-string-theory-falsifiable},
12+
title = {{Is String theory falsifiable?}},
13+
titleaddon = {Can a theory that isn't completely testable still be useful to physics?},
14+
author = {Rafael Alves Batista and Joel Primack},
15+
date = {circa 2017},
16+
urldate = {2020-11-12}
17+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@online{jones2020,
2+
url = {https://www.thoughtco.com/what-is-string-theory-2699363},
3+
title = {{The Basics of String Theory}},
4+
author = {Andrew Zimmerman Jones},
5+
date = {2019-03-02},
6+
urldate = {2020-11-12}
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Content With Both Bibliographies
3+
author: My Author
4+
date: 2020-10-16
5+
summary: "This content has both individual and global bibliography files."
6+
---
7+
## Both Bibliographies Test
8+
9+
This content references citations from both individual [@jones2020] and global [@mann2019] bibliography files.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Content With Custom Global Bibliography
3+
author: My Author
4+
date: 2020-10-16
5+
summary: "This content uses custom global bibliography files."
6+
---
7+
## Custom Global Bibliography Test
8+
9+
This content references citations that should be found in custom global bibliography files [@siegel2015; @castelvecchi2016].
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Content With Global Bibliography
3+
author: My Author
4+
date: 2020-10-16
5+
summary: "This content uses global bibliography files."
6+
---
7+
## Global Bibliography Test
8+
9+
This content references citations that should be found in global bibliography files [@mann2019; @wood2019].
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Content With Multiple Global Bibliographies
3+
author: My Author
4+
date: 2020-10-16
5+
summary: "This content uses multiple global bibliography files."
6+
---
7+
## Multiple Global Bibliographies Test
8+
9+
This content references citations from multiple global bibliography files [@francis2019; @alves2017].
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Content Without Bibliography
3+
author: My Author
4+
date: 2020-10-16
5+
summary: "This content has no bibliography files."
6+
---
7+
## No Bibliography Test
8+
9+
This content has no citations and no bibliography files should be found.

0 commit comments

Comments
 (0)