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

Add {filename} and {filename_without_extension} in templating #19

Open
wants to merge 1 commit into
base: main
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
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,25 @@ positional arguments:
options:
-h, --help show this help message and exit
--pdf-rename-pattern PDF_RENAME_PATTERN
Pattern to rename the pdf file. All entries of the metadata can be used as placeholders.
Placeholder must be in curly braces. Defaults to the title of the paper. Set to an empty
Pattern to rename the pdf file. All entries of the metadata can be used as placeholders.
Placeholder must be in curly braces. Defaults to the title of the paper. Set to an empty
string to not rename the pdf file.
--note-target-folder NOTE_TARGET_FOLDER
Folder where the note should be saved to. Can be an absolute path or relative to the
directory from wich the script is called. Defaults to the directory of the pdf file.
Folder where the note should be saved to. Can be an absolute path or relative to the
directory from wich the script is called. Defaults to the directory of the pdf file.
--note-template-path NOTE_TEMPLATE_PATH
Path to the note template. Can be an absolute path or relative to the directory from wich
Path to the note template. Can be an absolute path or relative to the directory from wich
the script is called. Defaults to a default note template.
--note-filename-pattern NOTE_FILENAME_PATTERN
Pattern to name the note file. All entries of the metadata can be used as placeholders.
Placeholder must be in curly braces. Defaults to the same name as the (renamed) pdf file.
Pattern to name the note file. All entries of the metadata can be used as placeholders.
Placeholder must be in curly braces. Defaults to the same name as the (renamed) pdf file.
```

### Context menu
As of now, the context menu entry is only available on windows. (I am happy to accept pull requests to add this functionality for other operating systems.)
As of now, the context menu entry is only available on windows. (I am happy to accept pull requests to add this functionality for other operating systems.)

#### Installation
The (default) command described above can also be executed by right-clicking on a pdf file and selecting the "paper2note" option.
The (default) command described above can also be executed by right-clicking on a pdf file and selecting the "paper2note" option.
To enable this functionality, execute the following command in a terminal with administrator rights:
```bash
paper2note-context-menu
Expand Down Expand Up @@ -102,7 +102,7 @@ options:


### Python Library
The utility can also be used as a python library.
The utility can also be used as a python library.
The library contains exactly one function, `paper2note`.
The following example shows how to create a reference note from a paper:
```python
Expand Down Expand Up @@ -134,6 +134,8 @@ Sometimes not all metadata can be extracted from the pdf file. In this case the
- `extraction_method`: The method used to extract the metadata from the pdf file
- `path`: The path to the (renamed) pdf file
- `relative_logseq_path`: If the pdf is located in a subdirectory of the logseq directory, this key contains the relative path to the pdf file from the logseq directory. Otherwise it is an empty string.
- `filename`: The name of the (renamed) pdf file (i.e. the final component of the path)
- `filename_without_extension`: The name of the (renamed) pdf file without the extension

## Accuracy of results
This utility uses the [pdf2bib](https://github.com/MicheleCotrufo/pdf2bib) library to extract metadata from the pdf file.
Expand Down
2 changes: 2 additions & 0 deletions paper2note/paper2note.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ def paper2note(
data["relative_logseq_path"] = str(get_relative_logseq_path(new_pdf_path)).replace(
"\\", "/"
)
data["filename"] = new_pdf_path.name
data["filename_without_extension"] = new_pdf_path.stem
# logger.info(f"Metadata extracted: {pprint.pformat(data)}")

### create note.md ###
Expand Down