Skip to content

Instantly share code, notes, and snippets.

@devmarkpro
Created February 9, 2025 04:50
Show Gist options
  • Select an option

  • Save devmarkpro/c5c82a38c58bdbfbb569955edcaae424 to your computer and use it in GitHub Desktop.

Select an option

Save devmarkpro/c5c82a38c58bdbfbb569955edcaae424 to your computer and use it in GitHub Desktop.
Embed All Documents in a Folder in Obsidian with Dataview.js

Embed All Documents in a Folder in Obsidian with Dataview.js

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 + "]]");
}
@AllieWade
Copy link
Copy Markdown

Bless you, kind soul. This is exactly what I needed.

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