Skip to content

Instantly share code, notes, and snippets.

@andreiRS
Last active Oct 6, 2021
Embed
What would you like to do?
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
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!");
}
@lwb52

This comment has been minimized.

Copy link

@lwb52 lwb52 commented Oct 4, 2021

as a ·js novice, where does this script go, & how do i invoke it??

@andreiRS

This comment has been minimized.

Copy link
Owner Author

@andreiRS andreiRS commented Oct 6, 2021

Hi @lwb52! You can find the original setup guide from @chhoumann documented here: https://github.com/chhoumann/quickadd/blob/master/docs/Examples/Macro_Zettelizer.md

@andreiRS

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment