Made a template to help with using Johnny.Decimal within an Obsidian vault

I use a JD-style folder structure for maintaining an Obsidian Vault. I found making new files cumbersome as I was often needing to make a new folder at the same time.

I ended up using the Templater plugin to create a folder template which is applied to the entire vault, which prompts for a name, creates a folder with that name with the correct index value, and moves the file to that folder.

<%*
if (tp.file.folder().split(" ")[0].length > 2) return;  // only operate on parents

// move file into the correct Johnny Decimal folder
const title = await tp.system.prompt("Name")
if (!title) return;
const folder = tp.file.find_tfile(tp.file.path(true)).parent
const last = folder.children
  .filter(f => !f.basename)  // filter to folders only
  .map(f => f.name.split(" ")[0]).sort().last();
const cat = folder.name.split(" ")[0];
const next = last ? String(Number(last.split(".")[1]) + 1).padStart(2, "0") : "01";
await tp.file.rename(title)
await tp.file.move(`${folder.path}/${cat}.${next} ${title}/${title}`)
-%>

Now, whenever I create a new file in eg “23 Locations”, it will automatically prompt for a name and create an appropriate folder with that name and move the new note to that folder. This way I can maintain the JD folder structure while still taking advantage of Obsidian wikilinks without excessive aliasing everywhere.

Thought I’d share it here in case anyone else found it useful.

5 Likes

Nice! I’ll add this to 31.01 Built for the system • Johnny.Decimal

Oh, man. This makes me want to go back to Obsidian… Really great work!