Skip to content

Commit 4c0de36

Browse files
committed
v0.0.15
2 parents d00996e + 7e08c5d commit 4c0de36

12 files changed

+70
-21
lines changed

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "obsidian-raindrop-highlights",
33
"name": "Raindrop Highlights",
4-
"version": "0.0.14",
4+
"version": "0.0.15",
55
"minAppVersion": "0.14.0",
66
"description": "Sync your Raindrop.io highlights.",
77
"author": "kaiiiz",

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obsidian-raindrop-highlights",
3-
"version": "0.0.14",
3+
"version": "0.0.15",
44
"description": "Sync your Raindrop.io highlights.",
55
"main": "main.js",
66
"scripts": {

src/api.ts

+4
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ export class RaindropAPI {
181181
created: new Date(raindrop['created']),
182182
type: raindrop['type'],
183183
important: raindrop['important'],
184+
creator: {
185+
name: raindrop['creatorRef']['name'],
186+
id: raindrop['creatorRef']['_id'],
187+
},
184188
};
185189
return bookmark;
186190
}

src/assets/defaultTemplate.njk

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
> [!{{callout}}]+ Updated on {{highlight.lastUpdate}}
2323
>
2424
> {{highlight.text.split("\n") | join("\n>")}}
25-
{% if highlight.note -%}> > {{highlight.note}}{%- endif %}
25+
{% if highlight.note -%}> > {{highlight.note + "\n"}}{%- endif %}
2626

2727
{%- endfor -%}

src/constants.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import DEFAULT_TEMPLATE from './assets/defaultTemplate.njk';
22
import type { RaindropPluginSettings } from "./types";
33

4-
export const VERSION = '0.0.14';
4+
export const VERSION = '0.0.15';
55

66
export const DEFAULT_SETTINGS: RaindropPluginSettings = {
77
version: VERSION,
88
username: undefined,
99
isConnected: false,
1010
ribbonIcon: true,
1111
appendMode: true,
12+
collectionsFolders: true,
1213
onlyBookmarksWithHl: false,
1314
highlightsFolder: '/',
1415
syncCollections: {},

src/main.ts

+4
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ export default class RaindropPlugin extends Plugin {
6969
});
7070

7171
this.addSettingTab(new RaindropSettingTab(this.app, this, this.api));
72+
73+
if (this.settings.autoSyncInterval) {
74+
this.startAutoSync();
75+
}
7276
}
7377

7478
async onunload() {

src/renderer.ts

+12-14
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ type RenderCollection = {
1717
title: string;
1818
};
1919

20+
type RenderCreator = {
21+
name: string,
22+
id: number,
23+
};
24+
2025
type RenderTemplate = {
2126
is_new_article: boolean;
2227
id: number;
@@ -30,6 +35,7 @@ type RenderTemplate = {
3035
created: string;
3136
type: string;
3237
important: boolean;
38+
creator: RenderCreator;
3339
};
3440

3541
const FAKE_RENDER_CONTEXT: RenderTemplate = {
@@ -56,6 +62,10 @@ const FAKE_RENDER_CONTEXT: RenderTemplate = {
5662
created: "2022-08-10T01:58:27.457Z",
5763
type: "link",
5864
important: false,
65+
creator: {
66+
name: 'fake_name',
67+
id: 10000,
68+
}
5969
};
6070

6171
export default class Renderer {
@@ -86,20 +96,7 @@ export default class Renderer {
8696

8797
renderFrontmatter(bookmark: RaindropBookmark, newArticle: boolean) {
8898
const newMdFrontmatter = this.renderTemplate(this.plugin.settings.metadataTemplate, bookmark, newArticle);
89-
let frontmatter: BookmarkFileFrontMatter = {
90-
raindrop_id: bookmark.id,
91-
raindrop_last_update: (new Date()).toISOString(),
92-
};
93-
try {
94-
frontmatter = {
95-
...frontmatter,
96-
...parseYaml(newMdFrontmatter),
97-
};
98-
} catch (e) {
99-
console.error(e);
100-
new Notice(`Failed to parse YAML for ${bookmark.title}: ${e.message}`)
101-
}
102-
return stringifyYaml(frontmatter);
99+
return `raindrop_id: ${bookmark.id}\nraindrop_last_update: ${(new Date()).toISOString()}\n${newMdFrontmatter}\n`
103100
}
104101

105102
renderFullArticle(bookmark: RaindropBookmark) {
@@ -142,6 +139,7 @@ export default class Renderer {
142139
created: Moment(bookmark.created).format(dateTimeFormat),
143140
type: bookmark.type,
144141
important: bookmark.important,
142+
creator: bookmark.creator,
145143
};
146144

147145
const content = nunjucks.renderString(template, context);

src/settings.ts

+14
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class RaindropSettingTab extends PluginSettingTab {
3434
this.ribbonIcon();
3535
this.onlyBookmarksWithHl();
3636
this.appendMode();
37+
this.collectionsFolders();
3738
this.highlightsFolder();
3839
this.collections();
3940
this.autoSyncInterval();
@@ -87,6 +88,19 @@ export class RaindropSettingTab extends PluginSettingTab {
8788
});
8889
}
8990

91+
private collectionsFolders(): void {
92+
new Setting(this.containerEl)
93+
.setName('Store the articles in collections folders')
94+
.addToggle((toggle) => {
95+
return toggle
96+
.setValue(this.plugin.settings.collectionsFolders)
97+
.onChange(async (value) => {
98+
this.plugin.settings.collectionsFolders = value;
99+
await this.plugin.saveSettings();
100+
});
101+
});
102+
}
103+
90104
private connect(): void {
91105
new Setting(this.containerEl)
92106
.setName('Connect to Raindrop.io')

src/sync.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ export default class RaindropSync {
3333
async syncCollection(collection: SyncCollection) {
3434
new Notice(`Sync Raindrop collection: ${collection.title}`);
3535
const highlightsFolder = this.plugin.settings.highlightsFolder;
36-
const collectionFolder = `${highlightsFolder}/${collection["title"]}`;
36+
let collectionFolder = `${highlightsFolder}`
37+
if (this.plugin.settings.collectionsFolders) {
38+
collectionFolder = `${highlightsFolder}/${collection["title"]}`;
39+
}
3740
const lastSyncDate = this.plugin.settings.syncCollections[collection.id].lastSyncDate;
3841

3942
let bookmarks: RaindropBookmark[] = [];
@@ -49,6 +52,15 @@ export default class RaindropSync {
4952
}
5053

5154
async syncBookmarks(bookmarks: RaindropBookmark[], folderPath: string) {
55+
if (bookmarks.length == 0) return;
56+
57+
if (this.plugin.settings.onlyBookmarksWithHl) {
58+
let requireUpdate = bookmarks.some((bookmark) => {
59+
return bookmark.highlights.length != 0;
60+
});
61+
if (!requireUpdate) return;
62+
}
63+
5264
try {
5365
await this.app.vault.createFolder(folderPath);
5466
} catch (e) {

src/templates/templateInstructions.html

+9-1
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,22 @@
1212
<li><span class="u-pop">{{title}}</span> (string) - Title</li>
1313
<li><span class="u-pop">{{excerpt}}</span> (string) - Article excerpt</li>
1414
<li><span class="u-pop">{{link}}</span> (string) - Link to source</li>
15-
<li><span class="u-pop">{{highlights}}</span> (string) - List of your Highlights</li>
15+
<li><span class="u-pop">{{highlights}}</span> (Highlight[]) - List of your Highlights (Detail attributes refer to the following <span class="u-pop">Highlight</span> section)</li>
16+
<li><span class="u-pop">{{collection}}</span> (Collection) - Collection data (Detail attributes refer to the following <span class="u-pop">Collection</span> section</li>
17+
<li><span class="u-pop">{{creator}}</span> (Creator) - Creator data (Detail attributes refer to the following <span class="u-pop">Creator</span> section</li>
1618
<li><span class="u-pop">{{tags}}</span> (string) - List of tag</li>
1719
<li><span class="u-pop">{{cover}}</span> (string) - Article cover</li>
1820
<li><span class="u-pop">{{created}}</span> (string) - Created on</li>
1921
<li><span class="u-pop">{{type}}</span> (string) - Article type</li>
2022
<li><span class="u-pop">{{important}}</span> (bool) - Favorite article</li>
2123
</ul>
2224

25+
Creator
26+
<ul>
27+
<li><span class="u-pop">{{name}}</span> (string) - Creator name</li>
28+
<li><span class="u-pop">{{id}}</span> (number) - Creator id</li>
29+
</ul>
30+
2331
Collection
2432
<ul>
2533
<li><span class="u-pop">{{title}}</span> (string) - Collection title</li>

src/types.ts

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ export interface RaindropHighlight { // Remote state
1818
text: string,
1919
}
2020

21+
export interface RaindropCreatorRef { // Remote state
22+
name: string,
23+
id: number,
24+
};
25+
2126
export interface RaindropBookmark { // Remote state
2227
id: number,
2328
collectionId: number,
@@ -31,6 +36,7 @@ export interface RaindropBookmark { // Remote state
3136
created: Date,
3237
type: string,
3338
important: boolean,
39+
creator: RaindropCreatorRef,
3440
}
3541

3642
// ----------
@@ -63,6 +69,7 @@ export interface RaindropPluginSettings {
6369
isConnected: boolean;
6470
ribbonIcon: boolean;
6571
appendMode: boolean;
72+
collectionsFolders: boolean;
6673
onlyBookmarksWithHl: boolean;
6774
highlightsFolder: string;
6875
syncCollections: SyncCollectionSettings;

versions.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
"0.0.11": "0.14.0",
1313
"0.0.12": "0.14.0",
1414
"0.0.13": "0.14.0",
15-
"0.0.14": "0.14.0"
15+
"0.0.14": "0.14.0",
16+
"0.0.15": "0.14.0"
1617
}

0 commit comments

Comments
 (0)