Skip to content

Instantly share code, notes, and snippets.

@RyotaUshio
Last active April 23, 2024 15:33
Show Gist options
  • Save RyotaUshio/ca6eae6b830e11a71b8fa101d5f05d67 to your computer and use it in GitHub Desktop.
Save RyotaUshio/ca6eae6b830e11a71b8fa101d5f05d67 to your computer and use it in GitHub Desktop.
My Template for Obsidian Zotero Integration
Error in user YAML: (<unknown>): found character that cannot start any token while scanning for the next token at line 1 column 2
---
{% if attachments -%}
PDF:
{%- for attachment in attachments | filterby("title", "endswith", ".pdf")%}
  - "[[{{ attachment.title }}]]"
{%- endfor %}
{%- endif %}
{% if accessDate -%}
accessDate: {{ accessDate | format('YYYY-MM-DD') }}
{%- endif %}
{% if allTags %}
allTags:
{%- for tag in allTags %}
  - "{{ tag }}"
{%- endfor %}
{%- endif  %}
{% if authors -%}
authors: 
{%- for author in authors.split(", ") %}
  - "[[{{author}}]]"
{%- endfor %}
{%- endif %}
bibliography: "{{ bibliography }}"
citekey: "{{ citekey }}"
date: {{ date | format('YYYY-MM-DD') }}
dateAdded: {{ dateAdded | format('YYYY-MM-DD') }}
dateModified: {{ dateModified | format('YYYY-MM-DD') }}
desktopURI: "{{ desktopURI }}"
exportDate: {{ exportDate | format('YYYY-MM-DD') }}
extra: "{{ extra | replace('\n', ' ') }}"
importDate: {{ importDate | format('YYYY-MM-DD') }}
isFirstImport: {{ isFirstImport }}
itemID: "{{ itemID }}"
itemKey: "{{ itemKey }}"
itemType: "{{ itemType }}"
key: "{{ key }}"
lastExportDate: {{ lastExportDate | format('YYYY-MM-DD') }}
lastImportDate: {{ lastImportDate | format('YYYY-MM-DD') }}
libraryCatalog: "{{ libraryCatalog }}"
libraryID: "{{ libraryID }}"
select: "{{ select }}"
title: "{{ title }}"
uri: "{{ uri }}"
url: "{{ url }}"
version: "{{ version }}"
year: {{date | format("YYYY")}}
shortAuthor: {% set n_authors = 0 -%}{%- for creator in creators -%}{%- if creator.creatorType == "author" -%}{%- set n_authors = n_authors + 1 -%}{%- endif -%}{%- endfor -%}{%- if n_authors == 1-%}{%- set authorString = creators[0].lastName -%}{%- elif n_authors == 2 -%}{%- set authorString = creators[0].lastName + " & " + creators[1].lastName -%}{%- else -%}{%- set authorString = creators[0].lastName + " et al." -%}{%- endif -%}"{{authorString}}"
formattedTitle: "{{title}} ({{authorString}}, {{date | format("YYYY")}})"
citet: "{{authorString}} ({{date | format("YYYY")}})"
citep: "({{authorString}}, {{date | format("YYYY")}})"
aliases:
  - "{{title}} ({{authorString}}, {{date | format("YYYY")}})"
  - "{{authorString}} ({{date | format("YYYY")}})"
  - "({{authorString}}, {{date | format("YYYY")}})"
---

{% if hashTags -%} {%- for tag in hashTags.split(', ') -%} {{ tag | replace('---', '/') }}{{ " " }} {%- endfor %}

{% endif -%} PDF: dv:this.PDF

{% if abstractNote -%}

[!abstract]+ {{ abstractNote | replace("\n", " ") }} ^abstract {% endif %}

{% persist "note" %}

{% endpersist %}

@RyotaUshio
Copy link
Author

RyotaUshio commented Apr 23, 2024

This is my template for the Obsidian Zotero Integration plugin.

A few notes:

  • I use ZotFile to auto-rename PDFs according to the following rule:
    {%t} ({%a}, {%y})
    
  • I put a symlink to my Zotero folder ~/Zotero/storage under the root of my vault so that all PDFs can be accessed from within Obsidian.
  • My "Output Path" option for Zotero Integration looks like the following. It looks terrible, but it will produce something like "Title (Author, 2024)", "Title (Author1 & Author2, 2024)" or "Title (Author1 et al., 2024)".
    Literature notes/{% set n_authors = 0 -%}{%- for creator in creators -%}{%- if creator.creatorType == "author" -%}{%- set n_authors = n_authors + 1 -%}{%- endif -%}{%- endfor -%}{%- if n_authors == 1-%}{%- set authorString = creators[0].lastName -%}{%- elif n_authors == 2 -%}{%- set authorString = creators[0].lastName + " & " + creators[1].lastName -%}{%- else -%}{%- set authorString = creators[0].lastName + " et al." -%}{%- endif -%}{%set title = title | replace("/", "-")%}{%set title = title | replace(":", "-")%}{{title}} ({{authorString}}, {{date | format("YYYY")}})/{{title}} ({{authorString}}, {{date | format("YYYY")}}).md
    
  • I've changed Dataview's "Inline Query Prefix" option to dv:.
  • For PDF annotation, I use my plugin PDF++ instead of Zotero.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment