Skip to content

Instantly share code, notes, and snippets.

@danieltomasz
Last active March 31, 2024 10:13
Show Gist options
  • Save danieltomasz/468e61fb90097555fed17ad8891c9f14 to your computer and use it in GitHub Desktop.
Save danieltomasz/468e61fb90097555fed17ad8891c9f14 to your computer and use it in GitHub Desktop.
Zotero Integration Obsidian new note template

I have several version of template I use with zotero.

One version of title is

literature/{{creators[0].lastName}}{{date | format ("YYYY")}} - {{title | replace("/" ,  "_") }}.md

Another, maybe easier to use in text when referring

literature/{{creators[0].lastName}}{{date | format ("YYYY")}} - {{title | replace("/" ,  "_") }}.md

and the content of the file (template is not mine, is taken from Obsidian Discord/Forum from @FeralFlora user and later modified by me)

---
title: "{{title}}"
authors: [{{authors}}]
year: {{date | format ("YYYY")}}
aliases: ["
    {%if creators -%}
        {{creators[0].lastName}}
        {%if creators|length > 1 %} et al.{% endif -%}
    {%endif -%}
    {%if date %} ({{date | format("YYYY")}}){% endif -%} 
    {%if shortTitle %} {{shortTitle | safe}} {%else %} {{title | safe}} {%endif -%}
", "@{{citekey}}"]
cite-tile: ["{%if creators -%}
        {{creators[0].lastName}}
        {%if (creators|length) > 1  and (creators|length < 3 %} {{creators[1].lastName}} {% endif -%}
        {%if creators|length > 2 %} et al.{% endif -%}
	    {%endif -%}
    {%if date %} ({{date | format("YYYY")}}){% endif -%} 
    {%if shortTitle %} {{shortTitle | safe}} {%else %} {{title | safe}} {%endif -%}"]
pdf-link: "zotero://open-pdf/library/items/{{attachments[0].itemKey}}/"
citekey: "{{citekey}}"
last-updated: {{importDate| format("YYYY-MM-DD")}}
---

# [{{title}}]({{desktopURI}})

{% persist "notes" %}  
{% if isFirstImport %}

## Processing

## Key Takeaways

## Metadata

- Status:: backlog
- Priority::
- Projects::
- Date-Read::
- Connections::

{% endif %}{% endpersist %}

> [!info]- Info - [**Zotero**]({{desktopURI}}) | [**DOI**](https://doi.org/{{DOI}}) | {% for attachment in attachments | filterby("path", "endswith", ".pdf") %}[**PDF**](file:///{{attachment.path | replace(" ", "%20")}}){%- endfor %}
>
> {% if bibliography %}**Bibliography**: {{bibliography|replace("\n"," ")}}{% endif %}
>
> **Authors**:: {% for a in creators %} [[{{a.firstName}} {{a.lastName}}]]{% if not loop.last %}, {% endif %}{% endfor %}
>
> {% if hashTags %}**Tags**: {{hashTags}}{% endif %}
>
> **Collections**:: {% for collection in collections %}[[{{collection.name}}]]{% if not loop.last %}, {% endif %}{% endfor %}
>
> **First-page**: {% for annotation in annotations %}{% if loop.first %}{{annotation.pageLabel}}{% endif %}{% endfor %}

> [!abstract]-  
> {% if abstractNote %}  
> {{abstractNote|replace("\n"," ")|striptags(true)|replace("Objectives", "**Objectives**")|replace("Background", "**Background**")|replace("Methodology", "**Methodology**")|replace("Results","**Results**")|replace("Conclusion","**Conclusion**")}}  
> {% endif %}

> [!quote]- Citations
>
> ```query
> content: "@{{citekey}}" -file:@{{citekey}}
> ```

## Reading Notes

{% macro calloutCharacter(color) -%}  
{%- if color == "#5fb236" -%}  
$  
{%- endif -%}  
{%- if color == "#2ea8e5" -%}  
@  
{%- endif -%}  
{%- if color == "#ffd400" -%}  
&  
{%- endif -%}  
{%- if color == "#a28ae5" -%}  
~  
{%- endif -%}  
{%- if color == "#ff6666" -%}  
!  
{%- endif -%}  
{%- if color == "#e56eee" -%}  
€  
{%- endif -%}  
{%- if color == "#f19837" -%}  
?  
{%- endif -%}  
{%- if color == "#aaaaaa" -%}  
%  
{%- endif -%}  
{%- endmacro -%}

{% persist "annotations" %}  
{% set annotations = annotations | filterby("date", "dateafter", lastImportDate) -%}  
{% if annotations.length > 0 %}  
*Imported on {{importDate | format("YYYY-MM-DD HH:mm")}}*  
{% for annotation in annotations -%}  
{%- if annotation.imageRelativePath %}

> [!cite]+ Image [(p. {{annotation.pageLabel}})](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.pageLabel}}&annotation={{annotation.id}})  
> ![[{{annotation.imageRelativePath}}]]{% if annotation.hashTags %}  
> {{annotation.hashTags}}{% endif %}{%- if (annotation.comment or []).indexOf("todo ") !== -1 %}
> - [ ] **{{annotation.comment | replace("todo ", "")}}**{% else %}  
> **{{annotation.comment}}**{%- endif %}

{%- elif (annotation.comment or []).indexOf("todo ") !== -1 %}

- [ ] **{{annotation.comment | replace("todo ", "")}}**:{% if not annotation.annotatedText %} [(p. {{annotation.pageLabel}})](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.pageLabel}}&annotation={{annotation.id}}){% else %}
	- {{calloutCharacter(annotation.color)}} {{annotation.annotatedText | nl2br}} [(p. {{annotation.pageLabel}})](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.pageLabel}}&annotation={{annotation.id}}) {% if annotation.hashTags %}{{annotation.hashTags}}{% endif -%}{% endif -%}  
{% elif annotation.comment %}
- **{{annotation.comment}}**:{% if not annotation.annotatedText %} [(p. {{annotation.pageLabel}})](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.pageLabel}}&annotation={{annotation.id}}){% else %}
	- {{calloutCharacter(annotation.color)}} {{annotation.annotatedText | nl2br}} [(p. {{annotation.pageLabel}})](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.pageLabel}}&annotation={{annotation.id}}) {% if annotation.hashTags %}{{annotation.hashTags}}{% endif -%}{% endif %}  
{%- elif annotation.annotatedText %}
- {{calloutCharacter(annotation.color)}} {{annotation.annotatedText | nl2br}} [(p. {{annotation.pageLabel}})](zotero://open-pdf/library/items/{{annotation.attachment.itemKey}}?page={{annotation.pageLabel}}&annotation={{annotation.id}}) {% if annotation.hashTags %}{{annotation.hashTags}}{% endif %}  
{%- endif -%}{%- endfor %}

{% endif %}  
{% endpersist %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment