Skip to content

Instantly share code, notes, and snippets.

@johannrichard
Last active August 4, 2024 13:55
Show Gist options
  • Save johannrichard/e567c257a5d5c74ad808080717722f3c to your computer and use it in GitHub Desktop.
Save johannrichard/e567c257a5d5c74ad808080717722f3c to your computer and use it in GitHub Desktop.
{#- Frontmatter Template - also called *Properties* in Obsidian -#}
---
id: {{ id }}
created: {{ updated }}
{# For fields like title and aliases, remove linebreaks and either add spaces (title, alias) or create multiple list entries (author) #}
title: "{{ title | replace('\n', ' ')}}"
aliases: ["{{ title | replace('\n', ' ') }}"{%- if sanitized_title %}, "{{sanitized_title}}"{%- endif %}]
author: ["{{ author | replace('\n', '", "')}}"]
category: "{{ category }}"
highlights: {{ num_highlights }}
last_highlight_at: {{ last_highlight_at }}
source: {{ unique_url }}
{# Replace special characters in tags. Eventually, some of that might end up in the plugin as well #}
tags: [ {%- if tags_nohash %}{{ tags_nohash | replace('&', 'and') | replace('@', '') }},{%- endif %}{%- if hl_tags_nohash %}{{ hl_tags_nohash | replace('&', 'and') | replace('@', '')}}{%- endif %} ]
---
{# Header Template
This is included once, and used to display variables of a Readwise Document (e.g. Author, Title, etc.) #}
%%
ID: {{ id }}
Updated: {{ updated }}
%%
# {{ title }}
{# Replace linebreaks and create multiple *Author* entries #}
_by: [[{{ author | replace('\n', ']], [[')}}]]_
> [!info]-
{%- if category == 'books' or category == 'supplementals' %}
> ![|300]( {{ cover_image_url }}) {% endif %}
> Authors: [[{{ author | replace('\n', ']], [[')}}]]
> Category: {{ category }}
> Number of Highlights: {{ num_highlights }}
> Readwise URL: {{ highlights_url }}
> Source URL: [{{ source_url }}]({{ source_url }})
> Date: [[{{ updated }}]]
> Last Highlighted: [[{{ last_highlight_at }}]]
{%- if summary %}
## Summary
{{ summary }}
^summary
{%- endif %}
---
{%- if document_note %}
## Document Note
{{ document_note }}
^document-note
{%- endif %}
## Incoming Links
{# This requires that the dataview plugin is installed. It will show all incoming links to this file #}
```dataview
LIST FROM [[]] SORT file.frontmatter.created DESC
```
## Highlights
{# After this heading, the highlights will follow, using the Highlight Template #}
{# Highlight template that does a few things:
- Convert Readwise's "Highlight" syntax (__Highlight__) to Obsidian Highlight Syntax (==Highlight==)
- Link to the Source and to the Highlight in Readwise
- Add block-id's both for the highlight and the note (Please be aware that line breaks, lists etc. in a note might create multiple blocks and referencing the "block-id-note" block might only link to the last block of the note.
#}
> [!quote]
> {{ text | bq | replace('__', '==') }}
{%- if category == 'books' %}
> (*Original*: [{{ location }}]({{ locationUrl }})){%endif %}
^{{ id }}
{%if note %}
{{ note }}
^{{ id }}-note
{% endif %}
({% if url %}[Source]({{ url }}), {% endif %}[Readwise](https://readwise.io/open/{{ id }}), [[{{ highlighted_at }}|{{ highlighted_at }}]])
----

What?

These three files are my (current) Templates for the Readwise Mirror plugin for Obsidian. They include (some) documentation.

Why?

They started to become complex enough to warrant some revision control, for which gist is perfect. They're probably useful for others too, hence the public gist.

How?

  • Install the plugin
  • Fill in the Header Template, the Frontmatter Template, and the Highlight Template
  • Use a Jinja Parser & Template engine (e.g. this one1 to preview the files.

Footnotes

  1. I'm not affiliated but found this one to be sufficiently simple to test basic templates. However, be aware that the plugin's own functions (e.g. bq) can not be parsed and rendered by third party parsers.

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