Skip to content

Commit 9d301cf

Browse files
committed
Complete Tag functionality
1 parent 38fb956 commit 9d301cf

File tree

5 files changed

+25
-5
lines changed

5 files changed

+25
-5
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.1.0 (2021-06-24)
4+
### Added
5+
- Added tag support, both in highlights and sources (books, articles, etc)
6+
37
## 1.0.2 (2021-05-24)
48
### Fixed
59
- Fixed linking bug when illegal characters were stripped in filename, but not in Note title (https://github.com/jsonMartin/readwise-mirror/issues/4)

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The first time this plugin is ran, it will do a full sync downloading all conten
1515
- Enhanced Obsidian Markdown formatting
1616
- Automatically creates `[[Links]]` for book titles and authors
1717
- Contains block level link references *(using the Highlight ID)*. Allows to automatically link/transclude any highlight without needing to modify the Readwise note.
18+
- Supports tags, both within highlights as well as sources (books, articles, etc)
1819

1920
## Usage
2021
After installing, visit the plugin configuration page to enter the Readwise Access Token, which can be found here: [https://readwise.io/access_token](https://readwise.io/access_token)

main.ts

+12-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { App, Plugin, PluginSettingTab, Setting } from 'obsidian';
22
import Notify from 'notify';
33
import spacetime from 'spacetime';
44

5-
import { ReadwiseApi, Library, Highlight, Book } from 'readwiseApi';
5+
import { ReadwiseApi, Library, Highlight, Book, Tag } from 'readwiseApi';
66

77
interface PluginSettings {
88
baseFolderName: string;
@@ -25,15 +25,22 @@ export default class ReadwiseMirror extends Plugin {
2525
readwiseApi: ReadwiseApi;
2626
notify: Notify;
2727

28+
private formatTags(tags: Tag[]) {
29+
return tags.map((tag) => `#${tag.name}`).join(', ');
30+
}
31+
2832
private formatHighlight(highlight: Highlight, book: Book) {
29-
const { id, text, note, location, color } = highlight;
33+
const { id, text, note, location, color, tags } = highlight;
3034
const locationUrl = `https://readwise.io/to_kindle?action=open&asin=${book['asin']}&location=${location}`;
3135
const locationBlock = location !== null ? `([${location}](${locationUrl}))` : '';
3236

37+
const formattedTags = tags.filter((tag) => tag.name !== color);
38+
const formattedTagStr = this.formatTags(formattedTags);
39+
3340
return `
3441
${text} ${book.category === 'books' ? locationBlock : ''}${color ? ` %% Color: ${color} %%` : ''} ^${id}${
3542
note ? `\n\n**Note: ${note}**` : ``
36-
}
43+
}${formattedTagStr.length >= 1 ? `\n\n**Tags: ${formattedTagStr}**` : ``}
3744
3845
---
3946
`;
@@ -74,6 +81,7 @@ ${text} ${book.category === 'books' ? locationBlock : ''}${color ? ` %% Color: $
7481
highlights,
7582
last_highlight_at,
7683
source_url,
84+
tags
7785
} = book;
7886
const sanitizedTitle = `${title.replace(':', '-').replace(/[<>"'\/\\|?*]+/g, '')}`;
7987

@@ -103,7 +111,7 @@ Updated: ${this.formatDate(updated)}
103111
# About
104112
Title: [[${sanitizedTitle}]]
105113
${authors.length > 1 ? 'Authors' : 'Author'}: ${authorStr}
106-
Category: #${category}
114+
Category: #${category}${tags.length > 1 ? ('\nTags: ' + this.formatTags(tags)): ''}
107115
Number of Highlights: ==${num_highlights}==
108116
Last Highlighted: *${last_highlight_at ? this.formatDate(last_highlight_at) : 'Never'}*
109117
Readwise URL: ${highlights_url}${category === 'articles' ? `\nSource URL: ${source_url}\n` : ''}

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "readwise-mirror",
33
"name": "Readwise Mirror",
4-
"version": "1.0.2",
4+
"version": "1.1.0",
55
"minAppVersion": "0.11.0",
66
"description": "Mirror your Readwise library directly to an Obsidian vault",
77
"author": "jsonmartin",

readwiseApi.ts

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ export interface Highlight {
1919
color: string;
2020
updated: string;
2121
book_id: number;
22+
tags: Tag[];
23+
}
24+
25+
export interface Tag {
26+
id: number;
27+
name: string;
2228
}
2329

2430
export interface Book {
@@ -34,6 +40,7 @@ export interface Book {
3440
source_url: string | null;
3541
asin: string;
3642
highlights: Highlight[];
43+
tags: Tag[];
3744
}
3845

3946
export interface Books {

0 commit comments

Comments
 (0)