This DataviewJS script dynamically embeds all documents from a specified folder (relative_folder_path) into a single file in Obsidian. It:
- Retrieves all notes from the given folder
- Sorts them by file name
- Generates embed links for each note (excluding the current one to prevent infinite loops)
Useful for creating an index or consolidated view of notes in a directory.
Make sure to enable Inline JavaScript Queries in the Dataview.js settings.
// Gather all pages in the Scratch directory
const pages = dv.pages('"relative_folder_path"')
// Sort by file name
.sort(page => page.file.path);
// For each page...
for (const page of pages) {
// (except this one -- no infinite loops!)
if (page.file.path == dv.current().file.path) { continue; }
// ...create an embed link.
dv.paragraph("- [[" + page.file.path + "]]");
}
Bless you, kind soul. This is exactly what I needed.