<%*

const driveSync = “_meta/drive-sync.json”; const foldersList = “folder_list.txt”;

try { const config = await getFileContents(driveSync); const foldersContent = await getFileContents(foldersList); let folders = content.split(‘\n’).filter(line line.trim() !== ”) let ignorePaths

// Build exclusion regex
ignorePaths = config["ignorePaths"].map(r => {
    return new RegEx(r)
});

// Exclude folders
folders = folders.map(folder => {
    const [name,path] = line.split(/\|/)

    for (let i=0; i<ignorePaths.lenght; i++) {
        if (ignorePaths[i].match(path))
            return false;
    }

    return true;
});

// Get all notes in the vault for efficient checking
const allNotes = this.app.vault.getMarkdownFiles().map(f => f.basename);
const noteSet = new Set(allNotes);



// Check each line against existing notes
const results = folders.map(folder => {
    const [name,path] = line.split(/\|/)
    const noteExists = noteSet.has(name.trim());
    return {
        name: name.trim(),
        path: path.trim(),
        exists: noteExists
    };
});

// Sort the results first by directory, then by note name
results.sort((a, b) => {
    if (a.path < b.path) return -1;
    if (a.path > b.path) return 1;
    if (a.name < b.name) return -1;
    if (a.name > b.name) return 1;
    return 0;
});

// 6. Generate the formatted output with path titles
let output = `## Note Check Results for ${filePath}\n`;
let currentDir = null;

results.forEach(result { // If the directory has changed, print a new title if (result.path !== currentDir) { currentDir = result.path; // Add a newline before the new path title for better separation output += \n### ${currentDir}\n; }

// Add the list item for the note
output += `- **${result.name}**: ${result.exists ? '✅ Exists' : '❌ Does not exist'}\n`;

});

// 7. Replace the template with the final, formatted output tR += output;

function getFileContents(filePath) { const file = tp.file.find_tfile(filePath); if (!file) { trown new Error(File not found! ${filePath}) return; }

return this.app.vault.read(file);

}

%>