Add full year option to formatter
This commit is contained in:
parent
f2d8306f1f
commit
12f0935ed4
2 changed files with 45 additions and 14 deletions
40
README.md
40
README.md
|
@ -30,20 +30,40 @@ or `Harvey22reflectionsacademiclife` (for Harvey, D. (2022). Reflections on an a
|
|||
## Configuration
|
||||
|
||||
No configuration except for the above setup is required for the formatting to work,
|
||||
but you can set a couple additional ones to customize the bevhavior to your liking:
|
||||
|
||||
### Title length
|
||||
|
||||
Currently, you can change the length that the `TitleShort` in `Name2008TitleShort` will be cut down to by setting
|
||||
the maximum length in words `title-words=4` or in characters `title-chars=20` under the `[plugins.bbt-formatter]` section in your papis configuration file (usually located at `~/.config/papis/config`).
|
||||
|
||||
To set a maximum word length, do:
|
||||
but you can set a couple additional ones to customize the behavior to your liking.
|
||||
Listed below are all options with their defaults:
|
||||
|
||||
```cfg
|
||||
[settings]
|
||||
formater = bbt
|
||||
ref-format = bbt
|
||||
|
||||
[plugins.bbt-formatter]
|
||||
fallback = python
|
||||
full-year = False
|
||||
title-words = 4
|
||||
title-chars = -1
|
||||
```
|
||||
|
||||
### Full year
|
||||
|
||||
You can specifiy whether the reference should contain the full 4-digit year representation (i.e. `1997`, `2018`) or just a shortened 2-digit version (`97`, `18`):
|
||||
|
||||
```cfg
|
||||
[plugins.bbt-formatter]
|
||||
full-year = True
|
||||
```
|
||||
|
||||
This will insert the full 4-digit publication year instead of the (default) shortened version.
|
||||
|
||||
### Title length
|
||||
|
||||
You can change the length that the `TitleShort` in `Name2008TitleShort` will be cut down to by setting
|
||||
the maximum length in words `title-words=4` or in characters `title-chars=20` under the `[plugins.bbt-formatter]` section in your papis configuration file (usually located at `~/.config/papis/config`).
|
||||
|
||||
To set a maximum word length, do:
|
||||
|
||||
```cfg
|
||||
[plugins.bbt-formatter]
|
||||
title-words = 4
|
||||
```
|
||||
|
@ -93,8 +113,8 @@ Can be any of the installed papis formatters, including custom ones
|
|||
|
||||
---
|
||||
|
||||
For now this plugin is a rather simple adaption from [this](https://github.com/hrdl-github/papis/commit/b9b9c6eaa3de159e1b210174ef49e90a89271eb8) commit,
|
||||
turned into an installable papis plugin and extended slightly.
|
||||
This plugin is a fairly simple adaption from [this](https://github.com/hrdl-github/papis/commit/b9b9c6eaa3de159e1b210174ef49e90a89271eb8) commit,
|
||||
turned into an installable papis plugin and extended a bit.
|
||||
|
||||
If you spot a bug or have an idea feel free to open an issue.\
|
||||
I might be slow to respond but will consider them all!
|
||||
|
|
|
@ -36,11 +36,9 @@ class BBTFormatter(papis.format.Formater):
|
|||
if "author" in doc
|
||||
else "UNKNOWN"
|
||||
)
|
||||
title_unfmt = doc["title"] if "title" in doc else "NO TITLE"
|
||||
year_unfmt = str(doc["year"]) if "year" in doc else "0000"
|
||||
author = re.sub("[^a-z]+", "", author_unfmt.lower())
|
||||
year = year_unfmt[-2:]
|
||||
title = self.get_title(title_unfmt)
|
||||
year = self.get_year(int(doc["year"]) if "year" in doc else 0000)
|
||||
title = self.get_title(doc["title"] if "title" in doc else "NO TITLE")
|
||||
return f"{author}{year}{title}"
|
||||
else:
|
||||
# TODO find less hacky way of calling another formatter?
|
||||
|
@ -54,7 +52,20 @@ class BBTFormatter(papis.format.Formater):
|
|||
papis.format._FORMATER = None
|
||||
return formatter
|
||||
|
||||
def get_year(self, year: int) -> str:
|
||||
"""Returns year string according to set year display options.
|
||||
|
||||
Returns either the full 4-digit year or a shortened 2-digit
|
||||
version depending on the plugin year options. """
|
||||
if papis.config.getboolean("full-year", "plugins.bbt-formatter"):
|
||||
return str(year)
|
||||
return str(year)[-2:]
|
||||
|
||||
def get_title(self, title: str) -> str:
|
||||
"""Returns cleaned and shortened title.
|
||||
|
||||
Removes skip-words, cleans any punctuation and spaces and trims
|
||||
the title length to that set in plugin length options."""
|
||||
title = re.sub("[^0-9a-z ]+", "", title.lower())
|
||||
title_words = list(
|
||||
map(
|
||||
|
|
Loading…
Reference in a new issue