Created
July 30, 2021 21:47
-
-
Save ngraham20/bb1528357bb692baacffc5fb3943c0a0 to your computer and use it in GitHub Desktop.
Obsidian Templater Script to Generate Folder Links
This file contains hidden or 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 function will generate links to every file in the same folder as this one | |
// use <%tp.user.folder_links(tp.file.path(), tp.file.title)%> to generate the list. | |
// The main use of this is if the notes are organized "Wiki style", with a file in | |
// each folder that matches the folder name, i.e. | |
// notes/ | |
// ├─ notes.md | |
// ├─ stickynotes/ | |
// │ ├─ stickynotes.md | |
// │ ├─ dec-21-2020.md | |
// ├─ school/ | |
// │ ├─ school.md | |
// │ ├─ chemistry/ | |
// │ │ ├─ chemistry.md | |
function folder_links(fullpath, title) { | |
fullpath = fullpath.replaceAll(/\//ig, '\\'); | |
fullpath = fullpath.substring(0, fullpath.lastIndexOf("\\")); | |
var fs = require('fs'); | |
var files = fs.readdirSync(fullpath); | |
var outfiles = []; | |
for (let f in files) { | |
let filetitle = files[f].replace(/\.[^/.]+$/, ""); | |
if (filetitle != title) { | |
outfiles.push(filetitle); | |
} | |
} | |
return "Links: [[" + outfiles.join("]], [[") + "]]"; | |
} | |
module.exports = folder_links |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment