Skip to content

Instantly share code, notes, and snippets.

@BunnyNoBugs
Created January 22, 2025 12:59
Show Gist options
  • Save BunnyNoBugs/781ad1b1a09fa6cb5ca23303836743c9 to your computer and use it in GitHub Desktop.
Save BunnyNoBugs/781ad1b1a09fa6cb5ca23303836743c9 to your computer and use it in GitHub Desktop.
BunnyNoBugs' Obsidian Zotero import template
Error in user YAML: (<unknown>): found character that cannot start any token while scanning for the next token at line 1 column 8
---
type: {% if itemType == "book" %}
    - book{% else %}
    - paper{% endif %}
title: "{% if creators -%}{{creators[0].lastName}}
        {%- if creators|length == 2 %} & {{creators[1].lastName}}{% endif -%}
        {%- if creators|length > 2 %} et al.{% endif -%}
        {%- endif -%}
        {%- if date %} ({{date | format("YYYY")}}){% endif -%}
        {%- if shortTitle %} {{shortTitle | nl2br}} {%- else %} {{title | nl2br}}
        {%- endif -%}"
zotero tags: {% for tag in tags %}
    - "{{tag.tag}}"{% endfor %}
created: {{importDate|format("DD.MM.YYYY")}}
modified: {{importDate|format("DD.MM.YYYY")}}
---

{#- METADATA AND PERMANENT INDEX -#} {#- This part only gets inserted once -#} {#- You can use this space to take permanent notes, e.g. to create an index or write a summary, or link to other notes #} {% persist "notes" %}{% if isFirstImport %}

{{title}}

πŸ“‡ Index

[!info]+ Metadata – {% for attachment in attachments | filterby("path", "endswith", ".pdf") %}PDF{% if not loop.first %} {{loop.index}}{% endif %}}}){% if not loop.last %}, {% endif %}{% endfor %} {{bibliography}}

  • Keywords:
  • Zotero: Open entry{% if relations %}
  • Related: {% for relation in relations %}{% if relation.citekey %}[[@{{relation.citekey}}]]{% if not loop.last %}, {% endif %}{% endif %}{% endfor %}{% endif %}

[!example]- Abstract {{abstractNote | nl2br}}

[!note]+ Notes

{% endif %}{% endpersist %}

{% persist "annotations" %} {#- WARNING: Everything below this line will get overwritten on re-import! -#} {#- COLOR VARIABLES -#} {%- set zoteroColors = { "#ffd400": "yellow", "#ff6666": "red", "#5fb236": "green", "#2ea8e5": "blue", "#a28ae5": "purple", "#f19837": "orange", "#e56eee": "magenta", "#aaaaaa": "grey" } -%}

{%- set colorHeading = { "blue": "Blue", "yellow": "⭐ Highlights", "red": "🚨 Important points", "green": "πŸ“š Ideas, Further Reading", "purple": "Purple", "magenta": "❓ Questions", "other": "Misc" } -%}

{#- ANNOTATION TYPES -#} {%- macro calloutHeader(type) -%} {%- switch type -%} {%- case "highlight" -%} Highlight {%- case "image" -%} Image {%- default -%} Note {%- endswitch -%} {%- endmacro %}

{#- SET CUSTOM ANNOTATION COLORS -#} {%- set newAnnot = [] -%} {%- set newAnnotations = [] -%} {%- set annotations = annotations | filterby("date", "dateafter", lastImportDate) %}

{% if annotations.length > 0 %}Imported: {{importDate | format("YYYY-MM-DD HH:mm")}}

{%- for annot in annotations -%}

{%- if annot.color in zoteroColors -%}
    {%- set customColor = zoteroColors[annot.color] -%}
{%- elif annot.colorCategory|lower in colorHeading -%}
	{%- set customColor = annot.colorCategory|lower -%}
{%- else -%}
    {%- set customColor = "other" -%}
{%- endif -%}

{%- set newAnnotations = (newAnnotations.push({"annotation": annot, "customColor": customColor}), newAnnotations) -%}

{%- endfor -%}

{#- INSERT ANNOTATIONS -#} {#- Loops through each of the available colors and only inserts matching annotations -#} {#- This is a workaround for inserting categories in a predefined order (instead of using groupby & the order in which they appear in the PDF) -#}

{%- for color, heading in colorHeading -%} {%- for entry in newAnnotations | filterby ("customColor", "startswith", color) -%} {%- set annot = entry.annotation -%}

{%- if entry and loop.first %}

{{colorHeading[color]}}

{%- endif %}

[!quote{{"|" + color if color != "other"}}]+ {{calloutHeader(annot.type)}} (p. {{annot.pageLabel}})

{%- if annot.annotatedText %}

{% if annot.hashTags %}[[{{annot.hashTags|replace("#", "")}}]]: {% endif -%} {{annot.annotatedText|nl2br}} {%- endif %}

{%- if annot.imageRelativePath %}

![[{{annot.imageRelativePath}}]] {%- endif %}

{%- if annot.ocrText %}

{{annot.ocrText}} {%- endif %}

{%- if annot.comment %}

β†’ {{annot.comment|nl2br}} {%- endif -%}

{%- endfor -%} {%- endfor -%} {% endif -%} {% endpersist %}

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