Skip to content

Commit

Permalink
v0.0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiiiz committed Mar 14, 2023
2 parents d00996e + 7e08c5d commit 4c0de36
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 21 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-raindrop-highlights",
"name": "Raindrop Highlights",
"version": "0.0.14",
"version": "0.0.15",
"minAppVersion": "0.14.0",
"description": "Sync your Raindrop.io highlights.",
"author": "kaiiiz",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-raindrop-highlights",
"version": "0.0.14",
"version": "0.0.15",
"description": "Sync your Raindrop.io highlights.",
"main": "main.js",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ export class RaindropAPI {
created: new Date(raindrop['created']),
type: raindrop['type'],
important: raindrop['important'],
creator: {
name: raindrop['creatorRef']['name'],
id: raindrop['creatorRef']['_id'],
},
};
return bookmark;
}
Expand Down
2 changes: 1 addition & 1 deletion src/assets/defaultTemplate.njk
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
> [!{{callout}}]+ Updated on {{highlight.lastUpdate}}
>
> {{highlight.text.split("\n") | join("\n>")}}
{% if highlight.note -%}> > {{highlight.note}}{%- endif %}
{% if highlight.note -%}> > {{highlight.note + "\n"}}{%- endif %}

{%- endfor -%}
3 changes: 2 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import DEFAULT_TEMPLATE from './assets/defaultTemplate.njk';
import type { RaindropPluginSettings } from "./types";

export const VERSION = '0.0.14';
export const VERSION = '0.0.15';

export const DEFAULT_SETTINGS: RaindropPluginSettings = {
version: VERSION,
username: undefined,
isConnected: false,
ribbonIcon: true,
appendMode: true,
collectionsFolders: true,
onlyBookmarksWithHl: false,
highlightsFolder: '/',
syncCollections: {},
Expand Down
4 changes: 4 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export default class RaindropPlugin extends Plugin {
});

this.addSettingTab(new RaindropSettingTab(this.app, this, this.api));

if (this.settings.autoSyncInterval) {
this.startAutoSync();
}
}

async onunload() {
Expand Down
26 changes: 12 additions & 14 deletions src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ type RenderCollection = {
title: string;
};

type RenderCreator = {
name: string,
id: number,
};

type RenderTemplate = {
is_new_article: boolean;
id: number;
Expand All @@ -30,6 +35,7 @@ type RenderTemplate = {
created: string;
type: string;
important: boolean;
creator: RenderCreator;
};

const FAKE_RENDER_CONTEXT: RenderTemplate = {
Expand All @@ -56,6 +62,10 @@ const FAKE_RENDER_CONTEXT: RenderTemplate = {
created: "2022-08-10T01:58:27.457Z",
type: "link",
important: false,
creator: {
name: 'fake_name',
id: 10000,
}
};

export default class Renderer {
Expand Down Expand Up @@ -86,20 +96,7 @@ export default class Renderer {

renderFrontmatter(bookmark: RaindropBookmark, newArticle: boolean) {
const newMdFrontmatter = this.renderTemplate(this.plugin.settings.metadataTemplate, bookmark, newArticle);
let frontmatter: BookmarkFileFrontMatter = {
raindrop_id: bookmark.id,
raindrop_last_update: (new Date()).toISOString(),
};
try {
frontmatter = {
...frontmatter,
...parseYaml(newMdFrontmatter),
};
} catch (e) {
console.error(e);
new Notice(`Failed to parse YAML for ${bookmark.title}: ${e.message}`)
}
return stringifyYaml(frontmatter);
return `raindrop_id: ${bookmark.id}\nraindrop_last_update: ${(new Date()).toISOString()}\n${newMdFrontmatter}\n`
}

renderFullArticle(bookmark: RaindropBookmark) {
Expand Down Expand Up @@ -142,6 +139,7 @@ export default class Renderer {
created: Moment(bookmark.created).format(dateTimeFormat),
type: bookmark.type,
important: bookmark.important,
creator: bookmark.creator,
};

const content = nunjucks.renderString(template, context);
Expand Down
14 changes: 14 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class RaindropSettingTab extends PluginSettingTab {
this.ribbonIcon();
this.onlyBookmarksWithHl();
this.appendMode();
this.collectionsFolders();
this.highlightsFolder();
this.collections();
this.autoSyncInterval();
Expand Down Expand Up @@ -87,6 +88,19 @@ export class RaindropSettingTab extends PluginSettingTab {
});
}

private collectionsFolders(): void {
new Setting(this.containerEl)
.setName('Store the articles in collections folders')
.addToggle((toggle) => {
return toggle
.setValue(this.plugin.settings.collectionsFolders)
.onChange(async (value) => {
this.plugin.settings.collectionsFolders = value;
await this.plugin.saveSettings();
});
});
}

private connect(): void {
new Setting(this.containerEl)
.setName('Connect to Raindrop.io')
Expand Down
14 changes: 13 additions & 1 deletion src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export default class RaindropSync {
async syncCollection(collection: SyncCollection) {
new Notice(`Sync Raindrop collection: ${collection.title}`);
const highlightsFolder = this.plugin.settings.highlightsFolder;
const collectionFolder = `${highlightsFolder}/${collection["title"]}`;
let collectionFolder = `${highlightsFolder}`
if (this.plugin.settings.collectionsFolders) {
collectionFolder = `${highlightsFolder}/${collection["title"]}`;
}
const lastSyncDate = this.plugin.settings.syncCollections[collection.id].lastSyncDate;

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

async syncBookmarks(bookmarks: RaindropBookmark[], folderPath: string) {
if (bookmarks.length == 0) return;

if (this.plugin.settings.onlyBookmarksWithHl) {
let requireUpdate = bookmarks.some((bookmark) => {
return bookmark.highlights.length != 0;
});
if (!requireUpdate) return;
}

try {
await this.app.vault.createFolder(folderPath);
} catch (e) {
Expand Down
10 changes: 9 additions & 1 deletion src/templates/templateInstructions.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,22 @@
<li><span class="u-pop">{{title}}</span> (string) - Title</li>
<li><span class="u-pop">{{excerpt}}</span> (string) - Article excerpt</li>
<li><span class="u-pop">{{link}}</span> (string) - Link to source</li>
<li><span class="u-pop">{{highlights}}</span> (string) - List of your Highlights</li>
<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>
<li><span class="u-pop">{{collection}}</span> (Collection) - Collection data (Detail attributes refer to the following <span class="u-pop">Collection</span> section</li>
<li><span class="u-pop">{{creator}}</span> (Creator) - Creator data (Detail attributes refer to the following <span class="u-pop">Creator</span> section</li>
<li><span class="u-pop">{{tags}}</span> (string) - List of tag</li>
<li><span class="u-pop">{{cover}}</span> (string) - Article cover</li>
<li><span class="u-pop">{{created}}</span> (string) - Created on</li>
<li><span class="u-pop">{{type}}</span> (string) - Article type</li>
<li><span class="u-pop">{{important}}</span> (bool) - Favorite article</li>
</ul>

Creator
<ul>
<li><span class="u-pop">{{name}}</span> (string) - Creator name</li>
<li><span class="u-pop">{{id}}</span> (number) - Creator id</li>
</ul>

Collection
<ul>
<li><span class="u-pop">{{title}}</span> (string) - Collection title</li>
Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export interface RaindropHighlight { // Remote state
text: string,
}

export interface RaindropCreatorRef { // Remote state
name: string,
id: number,
};

export interface RaindropBookmark { // Remote state
id: number,
collectionId: number,
Expand All @@ -31,6 +36,7 @@ export interface RaindropBookmark { // Remote state
created: Date,
type: string,
important: boolean,
creator: RaindropCreatorRef,
}

// ----------
Expand Down Expand Up @@ -63,6 +69,7 @@ export interface RaindropPluginSettings {
isConnected: boolean;
ribbonIcon: boolean;
appendMode: boolean;
collectionsFolders: boolean;
onlyBookmarksWithHl: boolean;
highlightsFolder: string;
syncCollections: SyncCollectionSettings;
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
"0.0.11": "0.14.0",
"0.0.12": "0.14.0",
"0.0.13": "0.14.0",
"0.0.14": "0.14.0"
"0.0.14": "0.14.0",
"0.0.15": "0.14.0"
}

0 comments on commit 4c0de36

Please sign in to comment.