generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
67 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
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,47 @@ | ||
module.exports = async (params) => { | ||
console.log("Starting...") | ||
console.log(params); | ||
const currentFile = params.app.workspace.getActiveFile(); | ||
if (!currentFile) { | ||
new Notice("No active file."); | ||
return; | ||
} | ||
console.log("Found active file: ", currentFile.basename); | ||
|
||
const currentFileCache = params.app.metadataCache.getFileCache(currentFile); | ||
const headingsInFile = currentFileCache.headings; | ||
if (!headingsInFile) { | ||
new Notice(`No headers in file ${currentFile.name}`); | ||
return; | ||
} | ||
console.log("Found headings in active file: ", headingsInFile); | ||
|
||
const folder = "40 Slipbox/44 Zettels"; | ||
if (!params.app.vault.adapter.exists(folder)) { | ||
new Notice(`Could not find folder ${folder}`); | ||
return; | ||
} | ||
|
||
console.log("Folder does exist: ", folder); | ||
|
||
headingsInFile.forEach(async heading => { | ||
console.log(`Checking ${heading.heading}. It is level ${heading.level}`); | ||
if (heading.level === 3) { | ||
const splitHeading = heading.heading.split(" "); | ||
const location = splitHeading[0].trim(); | ||
const text = splitHeading.length > 1 ? [...splitHeading.slice(1)].join(' ').trim() : ""; | ||
|
||
const path = `${folder}/${text.replace(/[\\,#%&\{\}\/*<>$\'\":@]*/g, '')}.md`; | ||
const content = `![[${currentFile.basename}#${location}${text ? " " + text : ""}]]`; | ||
|
||
console.log(`Path: ${path}.\nContent: ${content}`); | ||
|
||
if (text && !(await params.app.vault.adapter.exists(path))) | ||
await params.app.vault.create(path, content); | ||
else if (text) | ||
new Notice(`File ${path} already exists.`, 5000); | ||
} | ||
}); | ||
|
||
console.log("Finished!"); | ||
} |
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,19 @@ | ||
# Zettelizer | ||
![Zettelizer Demo](../Images/zettelizer_demo.gif) | ||
|
||
You can get the `.js` file for this userscript [here](./Attachments/zettelizer.js). | ||
To install it, you can follow the same process as in the [fetch tasks from Todoist example - with video](./Capture_FetchTasksFromTodoist.md). | ||
|
||
## Setup | ||
You will need to define the folder you want the script to place the new notes in. | ||
|
||
This can be done on line 19, where it says ``const folder = "..."``. Change the text inside the `""` to match the desired folder path. | ||
|
||
Currently, the script _only_ looks for level 3 headers. This means headers with three pound symbols, like so ``### header``. | ||
|
||
You can freely change this. On line 29 it says ``if (heading.level === 3)``. You can change this to any other number, denoting the heading level desired. You can also, rather than checking for equality (`===`), check for other conditions, such as `heading.level >= 1`, which denotes headers of level 1 or greater. | ||
|
||
The script looks for headers in your active file with the desired level. | ||
If such a header is found, it will ignore the first 'word' (any sequence of characters - i.e., letters, numbers, symbols, etc - followed by a space). Then, it will create a file with a name containing the remaining text in the heading. | ||
|
||
In that file, it will link to the heading it created the file from. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.