Skip to content

Commit

Permalink
v0.0.16
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiiiz committed Mar 21, 2023
2 parents 4c0de36 + a75e0ab commit dd1187f
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 13 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.15",
"version": "0.0.16",
"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.15",
"version": "0.0.16",
"description": "Sync your Raindrop.io highlights.",
"main": "main.js",
"scripts": {
Expand Down
29 changes: 22 additions & 7 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import axios from "axios";
import type { RaindropBookmark, RaindropCollection, RaindropHighlight, RaindropUser } from "./types";
import TokenManager from "./tokenManager";

const BASEURL = "https://api.raindrop.io/rest/v1"
const BASEURL = "https://api.raindrop.io/rest/v1";

interface NestedRaindropCollection {
title: string,
parentId: number,
}

export class RaindropAPI {
app: App;
Expand Down Expand Up @@ -42,35 +47,45 @@ export class RaindropAPI {

async getCollections(): Promise<RaindropCollection[]> {
let res = await this.get(`${BASEURL}/collections`, {});
const collectionMap: {[id: number]: string} = {};

let collections: RaindropCollection[] = [
{ id: -1, title: 'Unsorted' },
{ id: -99, title: 'Trash' },
];

const rootCollectionMap: {[id: number]: string} = {};
res.items.forEach((collection: any) => {
const id = collection['_id'];
const title = collection['title'];
collectionMap[id] = title;
rootCollectionMap[id] = title;
collections.push({
title: title,
id: id,
});
});

res = await this.get(`${BASEURL}/collections/childrens`, {});
const nestedCollectionMap: {[id: number]: NestedRaindropCollection} = {};
res.items.forEach((collection: any) => {
const id = collection['_id'];
nestedCollectionMap[id] = {
title: collection['title'],
parentId: collection['parent']['$id'],
};
});

res.items.forEach((collection: any) => {
const id = collection['_id'];
const parentId = collection['parent']['$id'];
let parentId = collection['parent']['$id'];
let title = collection['title'];
if (parentId in collectionMap) {
title = `${collectionMap[parentId]}/${collection['title']}`;
while (!(parentId in rootCollectionMap)) {
title = `${nestedCollectionMap[parentId].title}/${title}`;
parentId = nestedCollectionMap[parentId].parentId;
}
collections.push({
title: title,
id: id,
});
collectionMap[id] = title;
});

return collections;
Expand Down
2 changes: 1 addition & 1 deletion src/assets/defaultTemplate.njk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% if is_new_article %}
# Metadata
{% if link %}Source URL:: {{link}}{% endif %}
{% if tags|length %}Topics:: {{ tags | join(", ") }}{% endif %}
{% if tags|length %}Topics:: {{ tags | map("#{}") | join(", ") }}{% endif %}

---
# {{title}}
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import DEFAULT_TEMPLATE from './assets/defaultTemplate.njk';
import type { RaindropPluginSettings } from "./types";

export const VERSION = '0.0.15';
export const VERSION = '0.0.16';

export const DEFAULT_SETTINGS: RaindropPluginSettings = {
version: VERSION,
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface RaindropHighlight { // Remote state
export interface RaindropCreatorRef { // Remote state
name: string,
id: number,
};
}

export interface RaindropBookmark { // Remote state
id: number,
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
"0.0.12": "0.14.0",
"0.0.13": "0.14.0",
"0.0.14": "0.14.0",
"0.0.15": "0.14.0"
"0.0.15": "0.14.0",
"0.0.16": "0.14.0"
}

0 comments on commit dd1187f

Please sign in to comment.