generated from THeK3nger/obsidian-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Updated: refactored, formatted code, added code review suggestions.
- Loading branch information
jamesb
committed
Apr 28, 2021
1 parent
7931037
commit 44004c5
Showing
31 changed files
with
1,675 additions
and
1,585 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 |
---|---|---|
|
@@ -10,4 +10,4 @@ main.js | |
|
||
# Comment one of the following lock file in your plugin! | ||
pnpm-lock.yaml | ||
npm-lock.yaml | ||
npm-lock.yaml |
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,13 @@ | ||
dist/ | ||
|
||
# npm | ||
node_modules | ||
package-lock.json | ||
|
||
# Outputs | ||
main.js | ||
*.js.map | ||
|
||
# Comment one of the following lock file in your plugin! | ||
pnpm-lock.yaml | ||
npm-lock.yaml |
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 @@ | ||
{} |
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 +1,12 @@ | ||
{"vimMode":false,"defaultPriority":30,"queueFolderPath":"IW-Queues","queueFilePath":"queue.md","defaultAFactor":2,"defaultInterval":1,"defaultQueueType":"simple","defaultPriorityMin":35,"defaultPriorityMax":90,"skipAddNoteWindow":true} | ||
{ | ||
"vimMode": false, | ||
"defaultPriority": 30, | ||
"queueFolderPath": "IW-Queues", | ||
"queueFilePath": "queue.md", | ||
"defaultAFactor": 2, | ||
"defaultInterval": 1, | ||
"defaultQueueType": "afactor", | ||
"defaultPriorityMin": 27, | ||
"defaultPriorityMax": 85, | ||
"skipAddNoteWindow": true | ||
} |
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,10 +1,10 @@ | ||
{ | ||
"id": "obsidian-incremental-writing", | ||
"name": "Incremental Writing", | ||
"description": "Incrementally review notes and blocks over time.", | ||
"isDesktopOnly": true, | ||
"version": "0.3.4", | ||
"author": "Experimental Learning", | ||
"authorUrl": "https://github.com/bjsi/incremental-writing", | ||
"js": "main.js" | ||
} | ||
{ | ||
"id": "obsidian-incremental-writing", | ||
"name": "Incremental Writing", | ||
"description": "Incrementally review notes and blocks over time.", | ||
"isDesktopOnly": true, | ||
"version": "0.3.4", | ||
"author": "Experimental Learning", | ||
"authorUrl": "https://github.com/bjsi/incremental-writing", | ||
"js": "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
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,15 +1,15 @@ | ||
import typescript from "@rollup/plugin-typescript"; | ||
import { nodeResolve } from "@rollup/plugin-node-resolve"; | ||
import commonjs from "@rollup/plugin-commonjs"; | ||
|
||
export default { | ||
input: "./src/main.ts", | ||
output: { | ||
dir: ".", | ||
sourcemap: "inline", | ||
format: "cjs", | ||
exports: "default", | ||
}, | ||
external: ["obsidian"], | ||
plugins: [typescript(), nodeResolve({ browser: true }), commonjs()], | ||
}; | ||
import typescript from "@rollup/plugin-typescript"; | ||
import { nodeResolve } from "@rollup/plugin-node-resolve"; | ||
import commonjs from "@rollup/plugin-commonjs"; | ||
|
||
export default { | ||
input: "./src/main.ts", | ||
output: { | ||
dir: ".", | ||
sourcemap: "inline", | ||
format: "cjs", | ||
exports: "default", | ||
}, | ||
external: ["obsidian"], | ||
plugins: [typescript(), nodeResolve({ browser: true }), commonjs()], | ||
}; |
This file was deleted.
Oops, something went wrong.
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,40 +1,43 @@ | ||
import { ObsidianUtilsBase } from "./obsidian-utils-base" | ||
import { App, TFile } from "obsidian" | ||
import { ObsidianUtilsBase } from "./obsidian-utils-base"; | ||
import { App, TFile } from "obsidian"; | ||
|
||
export class BlockUtils extends ObsidianUtilsBase { | ||
constructor(app: App) { | ||
super(app); | ||
} | ||
|
||
constructor (app: App){ | ||
super(app); | ||
} | ||
|
||
// TODO: Rewrite | ||
getBlock(inputLine: string, noteFile: TFile): string { //Returns the string of a block ID if block is found, or "" if not. | ||
let noteBlocks = this.app.metadataCache.getFileCache(noteFile).blocks; | ||
console.log("Checking if line '" + inputLine + "' is a block."); | ||
let blockString = ""; | ||
if (noteBlocks) { // the file does contain blocks. If not, return "" | ||
for (let eachBlock in noteBlocks) { // iterate through the blocks. | ||
console.log("Checking block ^" + eachBlock); | ||
let blockRegExp = new RegExp("(" + eachBlock + ")$", "gim"); | ||
if (inputLine.match(blockRegExp)) { // if end of inputLine matches block, return it | ||
blockString = eachBlock; | ||
console.log("Found block ^" + blockString); | ||
return blockString; | ||
} | ||
} | ||
return blockString; | ||
} | ||
return blockString; | ||
// TODO: Rewrite | ||
getBlock(inputLine: string, noteFile: TFile): string { | ||
//Returns the string of a block ID if block is found, or "" if not. | ||
let noteBlocks = this.app.metadataCache.getFileCache(noteFile).blocks; | ||
console.log("Checking if line '" + inputLine + "' is a block."); | ||
let blockString = ""; | ||
if (noteBlocks) { | ||
// the file does contain blocks. If not, return "" | ||
for (let eachBlock in noteBlocks) { | ||
// iterate through the blocks. | ||
console.log("Checking block ^" + eachBlock); | ||
let blockRegExp = new RegExp("(" + eachBlock + ")$", "gim"); | ||
if (inputLine.match(blockRegExp)) { | ||
// if end of inputLine matches block, return it | ||
blockString = eachBlock; | ||
console.log("Found block ^" + blockString); | ||
return blockString; | ||
} | ||
} | ||
return blockString; | ||
} | ||
return blockString; | ||
} | ||
|
||
createBlockHash(): string { | ||
// Credit to https://stackoverflow.com/a/1349426 | ||
let result = ''; | ||
var characters = 'abcdefghijklmnopqrstuvwxyz0123456789'; | ||
var charactersLength = characters.length; | ||
for ( var i = 0; i < 7; i++ ) { | ||
result += characters.charAt(Math.floor(Math.random() * charactersLength)); | ||
} | ||
return result; | ||
createBlockHash(): string { | ||
// Credit to https://stackoverflow.com/a/1349426 | ||
let result = ""; | ||
var characters = "abcdefghijklmnopqrstuvwxyz0123456789"; | ||
var charactersLength = characters.length; | ||
for (var i = 0; i < 7; i++) { | ||
result += characters.charAt(Math.floor(Math.random() * charactersLength)); | ||
} | ||
return result; | ||
} | ||
} |
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,31 +1,28 @@ | ||
export class DateUtils { | ||
static addDays(date: Date, days: number) { | ||
var result = new Date(date); | ||
result.setDate(result.getDate() + days); | ||
return result; | ||
} | ||
static addDays(date: Date, days: number) { | ||
var result = new Date(date); | ||
result.setDate(result.getDate() + days); | ||
return result; | ||
} | ||
|
||
static formatDate(d: Date) { | ||
|
||
var month = '' + (d.getMonth() + 1); | ||
var day = '' + d.getDate(); | ||
var year = d.getFullYear(); | ||
static formatDate(d: Date) { | ||
var month = "" + (d.getMonth() + 1); | ||
var day = "" + d.getDate(); | ||
var year = d.getFullYear(); | ||
|
||
if (month.length < 2) | ||
month = '0' + month; | ||
if (day.length < 2) | ||
day = '0' + day; | ||
if (month.length < 2) month = "0" + month; | ||
if (day.length < 2) day = "0" + day; | ||
|
||
return [year, month, day].join('-'); | ||
} | ||
return [year, month, day].join("-"); | ||
} | ||
|
||
static isValid(date: Date) { | ||
return (date instanceof Date && !isNaN(date.valueOf())) | ||
} | ||
static isValid(date: Date) { | ||
return date instanceof Date && !isNaN(date.valueOf()); | ||
} | ||
|
||
static dateDifference(date1: Date, date2: Date) { | ||
const oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds | ||
// @ts-ignore | ||
return Math.round(Math.abs((date1 - date2) / oneDay)); | ||
} | ||
static dateDifference(date1: Date, date2: Date) { | ||
const oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds | ||
// @ts-ignore | ||
return Math.round(Math.abs((date1 - date2) / oneDay)); | ||
} | ||
} |
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,58 +1,63 @@ | ||
import { normalizePath, MarkdownView, App, TFile, TFolder } from "obsidian" | ||
import { ObsidianUtilsBase } from "./obsidian-utils-base" | ||
import { normalizePath, MarkdownView, App, TFile, TFolder } from "obsidian"; | ||
import { ObsidianUtilsBase } from "./obsidian-utils-base"; | ||
|
||
// TODO: read: https://github.com/lynchjames/obsidian-day-planner/blob/d1eb7ce187e7757b7a3880358a6ee184b3b025da/src/file.ts#L48 | ||
|
||
export class FileUtils extends ObsidianUtilsBase { | ||
|
||
constructor(app: App) { | ||
super(app); | ||
} | ||
|
||
async createIfNotExists(file: string, data: string) { | ||
const normalizedPath = normalizePath(file); | ||
if (!await this.app.vault.adapter.exists(normalizedPath)) { | ||
let folderPath = this.getParentOfNormalized(normalizedPath); | ||
await this.createFolders(folderPath); | ||
await this.app.vault.create(normalizedPath, data); | ||
} | ||
} | ||
|
||
toLinkText(file: TFile) { | ||
return this.app.metadataCache.fileToLinktext(file, file.path, true); | ||
} | ||
|
||
getParentOfNormalized(normalizedPath: string) { | ||
let pathSplit = normalizedPath.split('/'); | ||
return pathSplit.slice(0, pathSplit.length - 1).join('/'); | ||
} | ||
|
||
async createFolders(normalizedPath: string) { | ||
let current = normalizedPath; | ||
while (current && !await this.app.vault.adapter.exists(current)) { | ||
await this.app.vault.createFolder(current); | ||
current = this.getParentOfNormalized(current); | ||
} | ||
} | ||
|
||
isDescendantOf(file: TFile, folder: TFolder): boolean { | ||
let ancestor = file.parent; | ||
while (ancestor && !ancestor.isRoot()) { | ||
if (ancestor === folder) { | ||
return true; | ||
} | ||
ancestor = ancestor.parent; | ||
} | ||
return false; | ||
} | ||
|
||
async goTo(filePath: string, newLeaf: boolean) { | ||
let file = this.app.vault.getAbstractFileByPath(filePath) as TFile; | ||
let link = this.app.metadataCache.fileToLinktext(file, ""); | ||
await this.app.workspace.openLinkText(link, "", newLeaf); | ||
} | ||
|
||
getActiveNoteFile() { | ||
return (this.app.workspace.activeLeaf.view as MarkdownView).file; | ||
} | ||
constructor(app: App) { | ||
super(app); | ||
} | ||
|
||
async createIfNotExists(file: string, data: string) { | ||
const normalizedPath = normalizePath(file); | ||
if (!(await this.app.vault.adapter.exists(normalizedPath))) { | ||
let folderPath = this.getParentOfNormalized(normalizedPath); | ||
await this.createFolders(folderPath); | ||
await this.app.vault.create(normalizedPath, data); | ||
} | ||
} | ||
|
||
getTFile(filePath: string) { | ||
let file = this.app.vault.getAbstractFileByPath(filePath); | ||
if (file instanceof TFile) return file; | ||
return null; | ||
} | ||
|
||
toLinkText(file: TFile) { | ||
return this.app.metadataCache.fileToLinktext(file, "", true); | ||
} | ||
|
||
getParentOfNormalized(normalizedPath: string) { | ||
let pathSplit = normalizedPath.split("/"); | ||
return pathSplit.slice(0, pathSplit.length - 1).join("/"); | ||
} | ||
|
||
async createFolders(normalizedPath: string) { | ||
let current = normalizedPath; | ||
while (current && !(await this.app.vault.adapter.exists(current))) { | ||
await this.app.vault.createFolder(current); | ||
current = this.getParentOfNormalized(current); | ||
} | ||
} | ||
|
||
isDescendantOf(file: TFile, folder: TFolder): boolean { | ||
let ancestor = file.parent; | ||
while (ancestor && !ancestor.isRoot()) { | ||
if (ancestor === folder) { | ||
return true; | ||
} | ||
ancestor = ancestor.parent; | ||
} | ||
return false; | ||
} | ||
|
||
async goTo(filePath: string, newLeaf: boolean) { | ||
let file = this.app.vault.getAbstractFileByPath(filePath) as TFile; | ||
let link = this.app.metadataCache.fileToLinktext(file, ""); | ||
await this.app.workspace.openLinkText(link, "", newLeaf); | ||
} | ||
|
||
getActiveNoteFile() { | ||
return this.app.workspace.getActiveViewOfType(MarkdownView)?.file; | ||
} | ||
} |
Oops, something went wrong.