Skip to content

Instantly share code, notes, and snippets.

@TheFermi0n
Last active August 26, 2024 14:48
Show Gist options
  • Save TheFermi0n/7503c0a1d6accb83ffd423a540d45591 to your computer and use it in GitHub Desktop.
Save TheFermi0n/7503c0a1d6accb83ffd423a540d45591 to your computer and use it in GitHub Desktop.
Literature note template for Zotero Integration plugin

I would like to thank @FeralFlora for the original template. It is great in its own way and can produce a lot of output. However, I prefer a minimal approach, as there was a lot of redundant content for me. Moreover, I faced a problem with annotations not being copied when the HEX code of the color changes. Therefore, I modified the template to suit my preferences and fix the color issue by now checking the colorCategory instead of the HEX code itself (tested in Zotero 7 beta).

I hope this helps someone out there. To learn how to use it, please visit the original template gist.

The file below, named literatureNoteTemplate.md, is the template file.

PS. I would also like to share how I color-code my annotations below:

🟑 Important
πŸ”΄ Weaknesses and caveats
🟒 Main ideas and conclusions
πŸ”΅ Questions 
🟣 Definitions and concepts
🟠 Method
🟀 Hypotheses
βšͺ️ Survey instruments

{# v0.1 -#}

citekey: {{citekey}} libraryID: {{libraryID}} aliases:

  • "{%- if creators -%} {{creators[0].lastName or creators[0].name }} {%- if creators|length == 2 %} & {{creators[1].lastName or creators[1].name}}{% endif -%} {%- if creators|length > 2 %} et al.{% endif -%} {%- endif -%} {%- if date %} ({{date | format("YYYY")}}){% endif -%} {%- if shortTitle %} {{shortTitle | safe}} {%- else %} {{title | safe}} {%- endif -%}" {% if itemType == "bookSection" %} book-title: "{{bookTitle | replace('"',"'")}}" {% endif -%} title: "{{title | replace('"',"'") | capitalize}}" {%- set camelRegex = r/([a-z])([A-Z])/g %} {%- for type, creators in creators | groupby("creatorType") %} {% if creators.length > 1 %}{{type | replace(camelRegex, "$1 $2") | lower | trim}}s:{%- for creator in creators %}{% if creator.name %}
  • {{creator.name}}{% else%}
  • {{creator.firstName}} {{creator.lastName}} {% endif %}{%- endfor %} {% else -%} {{type | replace(camelRegex, "$1-$2") | lower | trim}}:{%- for creator in creators %}{% if creator.name %} "{{creator.name}}"{% else%} "{{creator.firstName}} {{creator.lastName}}"{% endif -%}{%- endfor -%}{% endif -%}{% endfor %} year: {% if date %}{{date | format("YYYY")}}{% endif %} item-type: {{itemType | replace(camelRegex, "$1 $2") | title | trim}} publisher: {% if publicationTitle %}"{{publicationTitle}}"{% else %}"{{publisher}}"{% endif %} {%- if notes.length > 0 -%} {%- set longShortCutoff = 20 -%} {%- set shortnotes = [] -%} {%- set longnotes = [] -%} {%- for note in notes -%} {%- if note.note | wordcount <= longShortCutoff -%} {%- set shortnotes = (shortnotes.push(note.note), shortnotes) -%} {%- else -%} {%- set longnotes = (longnotes.push(note), longnotes) -%} {%- endif -%}{%- endfor -%}{%- endif -%} {%- for comment in shortnotes %} {%- if comment and loop.first %} comments: {% endif -%}
  • "{{comment|replace('"',"'")| replace("\n"," ")}}"{% endfor %} tags: [{% for t in tags %}{{t.tag | replace(" ", "-")}}{% if not loop.last %}, {% endif %}{% endfor %}] {% if DOI -%} doi: https://doi.org/{{DOI}} {% endif -%} {%- if itemType == "book" -%} ISBN: {{ISBN}} {% endif -%} {% if date -%} date: {{date | format("YYYY-MM-DD")}} {% endif -%} status: reading collection: {% for c in collections %}{{c.name}}{% if not loop.last %}, {% endif %}{% endfor %}

Details

  • Authors: {% for c in creators %} {{c.firstName}} {{c.lastName}}{% if not loop.last %}, {% endif %}{% endfor %} {%- if relations.length > 0%}
  • Relations:{% for r in relations %}{% if loop.length == 1%} {{r.title}}{% else %} {{loop.index}}. [[{{r.title}}]]{% endif %}{% endfor %}{% endif %}
  • DOI: {{DOI}}
  • Zotero: {{desktopURI}}
  • PDF:{% for a in attachments | filterby("path", "endswith", ".pdf") %}{% if loop.length == 1%} [{{a.title}}](file:///{{a.path | replace(" ", "%20")}}){% else %} {{loop.index}}. [{{a.title}}](file:///{{a.path | replace(" ", "%20")}}){% endif %}{%- endfor %}

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

Keynotes

{#- The following is a cursor placeholder for the Templater plugin. After importing the note, you can jump to each of these with an assigned hotkey like Alt+Tab #}

  • <% tp.file.cursor(1) %>

{% endif %}{% endpersist %}{% if abstractNote %}

Abstract

{{abstractNote|replace("\n","\n>")|striptags(true)|replace("Objectives", "Objectives")|replace("Background", "Background")|replace("Methodology", "Methodology")|replace("Results","Results")|replace("Conclusion","Conclusion")}} {% endif %}

Notes

{% set colorValueMap = { "Yellow": {"heading": "🟑 Important"}, "Red": {"heading": "πŸ”΄ Weaknesses and caveats"}, "Green": {"heading": "🟒 Main ideas and conclusions"}, "Blue": {"heading": "πŸ”΅ Questions"}, "Purple": {"heading": "🟣 Definitions and concepts"}, "Orange": {"heading": "🟠 Method"}, "Magenta": {"heading": "🟀 Hypotheses"}, "Gray": {"heading": "βšͺ️ Survey instruments"} } -%}

{% persist "annotations" %} {% set annotations = annotations | filterby("date", "dateafter", lastImportDate) -%} {% if annotations.length > 0 %}

Imported on {{importDate | format("YYYY-MM-DD")}} at {{importDate | format("HH:mm")}}

{%- set grouped_annotations = annotations | groupby("colorCategory") -%} {%- for color, colorValue in colorValueMap -%} {%- if color in grouped_annotations -%} {%- set annotations = grouped_annotations[color] -%} {%- for annotation in annotations -%} {%- set citationLink = '[(p. ' ~ annotation.page ~ ')](zotero://open-pdf/library/items/' ~ annotation.attachment.itemKey ~ '?page=' ~ annotation.pageLabel ~ '&annotation=' ~ annotation.id ~ ')' %}

{%- if annotation and loop.first %}

{{colorValue.heading}}

{% endif -%}

{%- if annotation.imageRelativePath %}

[!cite]+ Image {{citationLink}} ![[{{annotation.imageRelativePath}}]]{% if annotation.hashTags %} {{annotation.hashTags}}{% endif %}{%- if (annotation.comment or []).indexOf("todo ") !== -1 %}

  • {{annotation.comment | replace("todo ", "")}}{%- elif annotation.comment %} {{annotation.comment}}{%- endif %} {% elif (annotation.comment or []).indexOf("todo ") !== -1 %} {{loop.index}}. [ ] {{annotation.comment | replace("todo ", "")}}:{% if not annotation.annotatedText %} {{citationLink}}{% else %} - {{annotation.annotatedText | nl2br}} {{citationLink}}{% if annotation.hashTags %} {{annotation.hashTags}}{% endif -%}{% endif -%} {% elif annotation.comment %} {{loop.index}}. {{annotation.comment}}:{% if not annotation.annotatedText %} {{citationLink}}{% else %} - {{annotation.annotatedText | nl2br}} {{citationLink}}{% if annotation.hashTags %} {{annotation.hashTags}}{% endif -%}{% endif %} {%- elif annotation.annotatedText %} {{loop.index}}. {{annotation.annotatedText | replace("\n", " ")}} {{citationLink}}{% if annotation.hashTags %} {{annotation.hashTags}}{% endif %} {%- endif -%}{%- endfor %}{%- endif -%} {% endfor %} {% endif %} {% endpersist -%}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment