The Self Discovery Channel on YouTube
I post videos discussing software, creativity, media, and video essays and short films. Please subscribe!
The above video goes over Jinja templates and using them to customize your highlights from Readwise.io into your Obsidian vault and some tips to get the most out of exports and how highlights taken from Readwise proper and Reader differ.
Jinja Templating Engine
Readwise uses Jinja for manipulating the highlights and other data taken from the items you add to Readwise. Through Jinja you can use if/then statements and text filters to fine tune the way your Obsidian highlight notes look.
Using Jinja templates you can customize your Obsidian notes by prepopulating tags based on ANY Readwise data point (Source, URL, Category, highlight date, etc). Using if/then logic you can set up entirely separate, customized templates for each type of article you highlight. Jinja also has some powerful filters that you can use to transform your Readwise data giving you tons of control with how it translates into your markdown notes - Like removing unwanted characters! Never let a tweet with hashtags mess up your Obsidian tags again!.
Plus, the community plugin Templater can also be used - Albeit not entirely! - inside your Readwise template when Templater is set to listen for and trigger on ANY new note creation.
Obsidian Export Templates
File Name
{{title|replace("#", "")|replace(";"," -")}} - {{author}}
The first section will take the {{title}} variable from Readwise and replace all instances of "#" with "", effectively removing them then it will go through the modified version of the {{title}} variable and replace all ";" with " -". For me, these were the most common characters popping up that were causing issues with file names in Obsidian notes. Chaining more |replace filters will let you continue to swap or remove characters.
Page Metadata
{% if is_new_page %}
{% if image_url -%}
![rw-book-cover|400]({{image_url}})
{% endif -%}{% endif -%}
The only change I made to the default value in this section is adding the '|400' after the embed image link. This will tell Obsidian to scale the image down to 400px width.
Highlights Header
{% if is_new_page %}
> [!INFO]+
> categorization:: {% for tag in document_tags %}#Subject/{{tag}} {% endfor %}
> classification:: #Source/{{"videos" if 'youtube.com' in url else category }}
> author:: {% if author %}[[{{author}}]]{% endif %}
> url:: {{url}}
> date:: [[{{last_highlighted_date|date('Y-m-d')}}]]
# Highlights
{% elif has_new_highlights -%}
## New highlights added [[{{date|date('Y-m-d')}}]]
{% endif -%}
Here we have a collapsible call out that will insert Obsidian tags (Starting with #Subject) for each Readwise tag added to the document. So tagging an article in Readwise as "Ghosties" will translate to a nested Obsidian tag of #Subject/Ghosties. For the #Source tag, which I use to track the type of item that is being highlighted, I have Readwise insert the type category that it internally uses unless the url of the item has 'youtube.com' in it. This is because Readwise's Reader app, that you can use to highlight transcripts of online video, does not translate t a 'video' category in Readwise proper, which is what is actually doing the exporting.
Highlight
> [!QUOTE]+
> {{ highlight_text|replace("#", "+") }}{% if highlight_location and highlight_location_url %} ([{{highlight_location}}]({{highlight_location_url}})){% elif highlight_location %} ({{highlight_location}}){% endif %} ^rw{{highlight_id}}
{% if highlight_tags %}
> [!IMPORTANT] Highlight Metadata
> Tags: {% for tag in highlight_tags %}[[{{tag}}]] {% endfor %}{% endif %}
{% if highlight_note %}> Note: {{ highlight_note|replace("#", "")|replace(":"," -") }}{% endif %}
YAML Front Matter
title: "{{title|replace("#", "")|replace(":"," -")}}"
moment: <% tp.date.now("HH:mm:SS") %>
icon: {{"📼" if 'youtube.com' in url else "📚" if category == "books" else "📰" if category == "articles" else "🐦" if category == "tweets" else "🎙" if category == "podcasts"}}
Sync Notification
I leave this disabled but I'm sure with some effort I could create a template for this note that would be useful in some way.
Relevant Links
- Readwise Obsidian Export Docs https://help.readwise.io/article/126-how-can-i-customize-the-readwise-to-obsidian-export#file-name
- Jinja Documentation https://jinja.palletsprojects.com/en/3.0.x/templates/
- Using Readwise’s highlight_id as a single source of truth in Obsidian by TfTHacker (Medium) https://tfthacker.medium.com/using-readwises-highlight-id-as-a-single-source-of-truth-in-obsidian-b1de98a8b87c