generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge: fix conflicts with rewritten version
- Loading branch information
Showing
12 changed files
with
1,270 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
# vscode | ||
.vscode | ||
|
||
# Intellij | ||
*.iml | ||
.idea | ||
|
||
# npm | ||
node_modules | ||
|
||
# Don't include the compiled main.js file in the repo. | ||
# They should be uploaded to GitHub releases instead. | ||
main.js | ||
|
||
# Exclude sourcemaps | ||
*.map | ||
|
||
# obsidian | ||
data.json | ||
|
||
# Exclude macOS Finder (System Explorer) View States | ||
.DS_Store | ||
tsconfig.tsbuildinfo | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? | ||
|
||
data.json |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,12 @@ | ||
{ | ||
"$schema": "https://biomejs.dev/schemas/1.4.1/schema.json", | ||
"organizeImports": { | ||
"enabled": true | ||
}, | ||
"organizeImports": { "enabled": true }, | ||
"linter": { | ||
"enabled": true, | ||
"rules": { | ||
"recommended": true | ||
} | ||
"rules": { "recommended": true } | ||
}, | ||
"formatter": { "indentStyle": "space" }, | ||
"javascript": { | ||
"formatter": { | ||
"enabled": true, | ||
"indentWidth": 2, | ||
"indentStyle": "space", | ||
"quoteStyle": "single" | ||
} | ||
}, | ||
"json": { | ||
"formatter": { | ||
"enabled": true, | ||
"indentWidth": 2, | ||
"indentStyle": "space" | ||
} | ||
"formatter": { "quoteStyle": "single" } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
"use strict"; | ||
var __defProp = Object.defineProperty; | ||
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; | ||
var __publicField = (obj, key, value) => { | ||
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); | ||
return value; | ||
}; | ||
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); | ||
const obsidian = require("obsidian"); | ||
class DailyHighlightsPlugin extends obsidian.Plugin { | ||
constructor() { | ||
super(...arguments); | ||
__publicField(this, "settings", {}); | ||
} | ||
getAuthHeaders() { | ||
return { | ||
AUTHORIZATION: `Token ${this.settings.readwiseAPIToken}` | ||
}; | ||
} | ||
getOfficialPluginSettings() { | ||
const plugins = this.app.plugins; | ||
const settings = plugins.plugins["readwise-official"].settings; | ||
return settings; | ||
} | ||
/** | ||
* If there's no token set, add a command to read it from the _official_ Readwise plugin settings. | ||
* (Assume that it's installed and enabled, I suppose.) | ||
* | ||
* Accessing the data from another plugin is questionable. I don't think it's explicitly | ||
* forbidden, but I also don't think it's intended. (The type definition for `this.app` | ||
* does not include `plugins`, so it's at minimum undocumented.) | ||
* | ||
* This is primarily for my own use, and it's gated behind a command the user has to choose, | ||
* though, so I'm not too worried about it. | ||
*/ | ||
async getTokenFromOfficialPlugin() { | ||
const apiToken = this.getOfficialPluginSettings().token; | ||
this.settings.readwiseAPIToken = apiToken; | ||
await this.saveSettings(); | ||
new obsidian.Notice("Successfully set Readwise API token"); | ||
} | ||
async getReview() { | ||
const response = await fetch(`https://readwise.io/api/v2/review/`, { | ||
method: "GET", | ||
headers: this.getAuthHeaders() | ||
}); | ||
const responseJson = await response.json(); | ||
console.log(responseJson); | ||
return responseJson; | ||
} | ||
/** | ||
* Find the note that contains the given highlight. Return the block-reference link. | ||
*/ | ||
highlightToMarkdown(highlight) { | ||
var _a; | ||
const bookIdsMap = this.getOfficialPluginSettings().booksIDsMap; | ||
const bookTitle = (_a = Object.entries(bookIdsMap).find(([_key, value]) => value === highlight.id.toString())) == null ? void 0 : _a[0]; | ||
return bookTitle; | ||
} | ||
async onload() { | ||
await this.loadSettings(); | ||
this.addRibbonIcon( | ||
"book-open", | ||
"Review highlights", | ||
async (_evt) => { | ||
new obsidian.Notice("This is a notice! I hope this changed."); | ||
await this.getTokenFromOfficialPlugin(); | ||
} | ||
); | ||
this.addCommand({ | ||
id: "add-review-highlights", | ||
name: "Add daily review highlights to current note", | ||
callback: async () => { | ||
await this.getTokenFromOfficialPlugin(); | ||
const review = await this.getReview(); | ||
const highlights = review.highlights; | ||
console.log(highlights); | ||
console.log(highlights.map(this.highlightToMarkdown.bind(this))); | ||
} | ||
}); | ||
this.addCommand({ | ||
id: "open-sample-modal-complex", | ||
name: "Open sample modal (complex)", | ||
checkCallback: (checking) => { | ||
const markdownView = this.app.workspace.getActiveViewOfType(obsidian.MarkdownView); | ||
if (markdownView) { | ||
if (!checking) { | ||
new SampleModal(this.app).open(); | ||
} | ||
return true; | ||
} | ||
} | ||
}); | ||
this.addCommand({ | ||
id: "find-readwise-token", | ||
name: "Set the Readwise API token from the official plugin settings", | ||
callback: this.getTokenFromOfficialPlugin.bind(this) | ||
}); | ||
this.addSettingTab(new SettingTab(this.app, this)); | ||
this.registerDomEvent(document, "click", (evt) => { | ||
console.log("click", evt); | ||
}); | ||
this.registerInterval( | ||
window.setInterval(() => console.log("setInterval"), 5 * 60 * 1e3) | ||
); | ||
} | ||
onunload() { | ||
} | ||
async loadSettings() { | ||
} | ||
async saveSettings() { | ||
await this.saveData(this.settings); | ||
} | ||
} | ||
class SampleModal extends obsidian.Modal { | ||
constructor(app) { | ||
super(app); | ||
} | ||
onOpen() { | ||
const { contentEl } = this; | ||
contentEl.setText("Woah!"); | ||
} | ||
onClose() { | ||
const { contentEl } = this; | ||
contentEl.empty(); | ||
} | ||
} | ||
class SettingTab extends obsidian.PluginSettingTab { | ||
constructor(app, plugin) { | ||
super(app, plugin); | ||
__publicField(this, "plugin"); | ||
this.plugin = plugin; | ||
} | ||
display() { | ||
const { containerEl } = this; | ||
containerEl.empty(); | ||
new obsidian.Setting(containerEl).setName("Readwise API token").setDesc( | ||
"API token from readwise.io. (Requires active Readwise subscription.)" | ||
).addText( | ||
(text) => text.setPlaceholder("n/a").setValue(this.plugin.settings.readwiseAPIToken).onChange(async (value) => { | ||
this.plugin.settings.readwiseAPIToken = value; | ||
await this.plugin.saveSettings(); | ||
}) | ||
); | ||
} | ||
} | ||
exports.default = DailyHighlightsPlugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
{ | ||
"id": "daily-readwise", | ||
"name": "Daily Readwise", | ||
"name": "Readwise highlights", | ||
"version": "1.0.0", | ||
"minAppVersion": "0.15.0", | ||
"description": "Integrate your Readwise daily review into your Obsidian daily note.", | ||
"minAppVersion": "1.0.0", | ||
"description": "Integrate Readwise daily reviews into Obsidian daily notes. This plugin is not affiliated with Readwise.", | ||
"author": "Tushar Chandra", | ||
"authorUrl": "", | ||
"fundingUrl": "", | ||
"authorUrl": "https://github.com/tuchandra", | ||
"isDesktopOnly": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,18 @@ | ||
{ | ||
"name": "daily-readwise", | ||
"version": "0.0.1", | ||
"description": "Link my Readwise daily review with my Obsidian vault.", | ||
"main": "main.js", | ||
"scripts-unclear": { | ||
"dev": "bun run esbuild.dev.config.mjs", | ||
"build": "tsc -noEmit -skipLibCheck && bun run esbuild.config.mjs production", | ||
"dev-publish": "bun run esbuild.publish.config.mjs", | ||
"build-publish": "tsc -noEmit -skipLibCheck && node esbuild.publish.config.mjs production" | ||
}, | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"tsc": "tsc -noEmit", | ||
"test": "bun test", | ||
"test:log": "LOG_TESTS=true bun test", | ||
"format": "bunx @biomejs/biome format .", | ||
"format:fix": "bunx @biomejs/biome format . --write", | ||
"lint": "biome check src/", | ||
"lint:fix": "biome check --apply src/", | ||
"check": "bun run format && bun run lint && bun run tsc && bun run test", | ||
"check:fix": "bun run format:fix && bun run lint:fix && bun run tsc && bun run test", | ||
"release": "bun run automation/release.ts" | ||
"dev": "vite build --watch", | ||
"build": "tsc && vite build", | ||
"preview": "vite preview", | ||
"format": "bunx @biomejs/biome format --write ." | ||
}, | ||
"keywords": [], | ||
"author": "tushar chandra", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@biomejs/biome": "1.4.1", | ||
"@types/node": "^16.11.6", | ||
"@typescript-eslint/eslint-plugin": "5.29.0", | ||
"@typescript-eslint/parser": "5.29.0", | ||
"builtin-modules": "3.3.0", | ||
"bun-types": "^1.0.18", | ||
"@biomejs/biome": "^1.4.1", | ||
"obsidian": "latest", | ||
"tslib": "2.4.0", | ||
"typescript": "^5.3.3" | ||
"typescript": "^5.2.2", | ||
"vite": "^5.0.8" | ||
} | ||
} | ||
} |
Oops, something went wrong.