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.
Transfer plugin to github template repo
- Loading branch information
0 parents
commit eef0787
Showing
16 changed files
with
2,646 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# top-most EditorConfig file | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = tab | ||
indent_size = 4 | ||
tab_width = 4 |
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,3 @@ | ||
node_modules/ | ||
|
||
main.js |
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,23 @@ | ||
{ | ||
"root": true, | ||
"parser": "@typescript-eslint/parser", | ||
"env": { "node": true }, | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
], | ||
"parserOptions": { | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"no-unused-vars": "off", | ||
"@typescript-eslint/no-unused-vars": ["error", { "args": "none" }], | ||
"@typescript-eslint/ban-ts-comment": "off", | ||
"no-prototype-builtins": "off", | ||
"@typescript-eslint/no-empty-function": "off" | ||
} | ||
} |
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,34 @@ | ||
name: Release Obsidian Plugin | ||
|
||
on: | ||
push: | ||
tags: | ||
- "*" | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Use Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: "18.x" | ||
|
||
- name: Build plugin | ||
run: | | ||
npm install | ||
npm run build | ||
- name: Create release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
tag="${GITHUB_REF#refs/tags/}" | ||
gh release create "$tag" \ | ||
--title="$tag" \ | ||
--draft \ | ||
main.js manifest.json styles.css |
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,22 @@ | ||
# 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 |
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 @@ | ||
tag-version-prefix="" |
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,11 @@ | ||
# Obsidian PDF to Images | ||
|
||
This plugin takes a pdf which is in the vault and converts them all to images, | ||
|
||
**Note:** The Obsidian API is still in early alpha and is subject to change at any time! | ||
|
||
**Dependencies:** | ||
https://github.com/yakovmeister/pdf2image/blob/master/docs/gm-installation.md | ||
|
||
## Usage | ||
Click on the icon to the left and select a pdf file from the vault. |
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,48 @@ | ||
import esbuild from "esbuild"; | ||
import process from "process"; | ||
import builtins from "builtin-modules"; | ||
|
||
const banner = | ||
`/* | ||
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD | ||
if you want to view the source, please visit the github repository of this plugin | ||
*/ | ||
`; | ||
|
||
const prod = (process.argv[2] === "production"); | ||
|
||
const context = await esbuild.context({ | ||
banner: { | ||
js: banner, | ||
}, | ||
entryPoints: ["main.ts"], | ||
bundle: true, | ||
external: [ | ||
"obsidian", | ||
"electron", | ||
"@codemirror/autocomplete", | ||
"@codemirror/collab", | ||
"@codemirror/commands", | ||
"@codemirror/language", | ||
"@codemirror/lint", | ||
"@codemirror/search", | ||
"@codemirror/state", | ||
"@codemirror/view", | ||
"@lezer/common", | ||
"@lezer/highlight", | ||
"@lezer/lr", | ||
...builtins], | ||
format: "cjs", | ||
target: "es2018", | ||
logLevel: "info", | ||
sourcemap: prod ? false : "inline", | ||
treeShaking: true, | ||
outfile: "main.js", | ||
}); | ||
|
||
if (prod) { | ||
await context.rebuild(); | ||
process.exit(0); | ||
} else { | ||
await context.watch(); | ||
} |
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,93 @@ | ||
import { App, Editor, MarkdownView, Modal, Notice, Menu, Plugin, PluginSettingTab, SuggestModal, Setting, TFile, Vault } from 'obsidian'; | ||
import { fromPath } from "pdf2pic"; | ||
|
||
// Remember to rename these classes and interfaces! | ||
|
||
interface ConvertPluginSettings { | ||
mySetting: string; | ||
} | ||
|
||
const DEFAULT_SETTINGS: ConvertPluginSettings = { | ||
mySetting: 'default' | ||
} | ||
|
||
export default class ConvertPlugin extends Plugin { | ||
settings: ConvertPluginSettings; | ||
|
||
async onload() { | ||
await this.loadSettings(); | ||
|
||
this.addRibbonIcon('file-down', 'Import PDF as image', (event) => { | ||
new FileModal(this.app).open(); | ||
}); | ||
|
||
// If the plugin hooks up any global DOM events (on parts of the app that doesn't belong to this plugin) | ||
// Using this function will automatically remove the event listener when this plugin is disabled. | ||
this.registerDomEvent(document, 'click', (evt: MouseEvent) => { | ||
}); | ||
|
||
// When registering intervals, this function will automatically clear the interval when the plugin is disabled. | ||
this.registerInterval(window.setInterval(() => console.log('setInterval'), 5 * 60 * 1000)); | ||
} | ||
|
||
onunload() { | ||
|
||
} | ||
|
||
async loadSettings() { | ||
this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); | ||
} | ||
|
||
async saveSettings() { | ||
await this.saveData(this.settings); | ||
} | ||
} | ||
|
||
|
||
export class FileModal extends SuggestModal<TFile> { | ||
getSuggestions(query: string): TFile[] | Promise<TFile[]> { | ||
return this.app.vault.getFiles().filter(t => { | ||
return t.extension.toLowerCase() == "pdf" && t.name.toLowerCase().includes(query.toLowerCase()); | ||
}) | ||
} | ||
|
||
renderSuggestion(value: TFile, el: HTMLElement) { | ||
el.createEl("div", {text: value.name}); | ||
el.createEl("small", {text: value.path}); | ||
} | ||
onChooseSuggestion(item: TFile, evt: MouseEvent | KeyboardEvent) { | ||
const baseOptions = { | ||
density: 100, | ||
preserveAspectRatio: true, | ||
format: "jpeg", | ||
saveFilename: item.basename, | ||
savePath: "", | ||
} | ||
const uri = this.app.vault.getResourcePath(item); | ||
const split = uri.split('/'); | ||
var filepath = ''; | ||
var savepath = ''; | ||
for(let i = 3; i < split.length - 1; i++) { | ||
filepath += split[i] + "/"; | ||
} | ||
|
||
savepath = decodeURI(filepath); | ||
filepath = decodeURI(filepath + item.name); | ||
|
||
baseOptions.savePath = savepath; | ||
const convert = fromPath(filepath, baseOptions).bulk(-1); | ||
convert.then((imagesList) => { | ||
const currentDoc = this.app.workspace.getActiveViewOfType(MarkdownView); | ||
if(currentDoc) { | ||
this.app.vault.process(currentDoc.file!, data => { | ||
imagesList.forEach((f) => { | ||
data += `![[${f.name}|500]]\n`; | ||
}) | ||
return data; | ||
}) | ||
|
||
} | ||
}) | ||
} | ||
|
||
} |
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,10 @@ | ||
{ | ||
"id": "obsidian-pdf-to-images", | ||
"name": "Import PDF as images", | ||
"version": "1.0.0", | ||
"minAppVersion": "0.15.0", | ||
"description": "Gets each page of the pdf and imports it as a series of images", | ||
"author": "JayGee0", | ||
"authorUrl": "https://github.com/JayGee0", | ||
"isDesktopOnly": false | ||
} |
Oops, something went wrong.