Last active
April 14, 2023 09:29
-
-
Save andreiRS/2310d5e84f4b049d6079ded7488f61f2 to your computer and use it in GitHub Desktop.
Extended the original zettelizer script to generate the zettels inside a folder with the same name as the source document. If you have also the plugin Zoottelkeeper installed, it will generate also an index file with the new notes. Example outcome: https://forum.obsidian.md/t/quickadd-plugin/20032/31
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
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 = `${currentFile.parent.path}/${currentFile.basename}`; | |
console.log("Create a new folder: ", folder); | |
if (!(await params.app.vault.adapter.exists(folder))) | |
await params.app.vault.createFolder(folder); | |
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!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example Outcome https://github.com/chhoumann/quickadd/blob/master/docs/Examples/Macro_Zettelizer.md
: