Trouble Generating journal links using user scripts in Templater

What I’m trying to do

I’m trying to make some links based of the existing entries in my journal folder using Templater and its user scripts functionality. i keep getting the following popup message: " Default export is not a function."

Things I have tried

i have tried to explicitly export my function and just plainly instert it into the template to no avail.

async function getJournalLinks() {
    const files = this.app.vault.getMarkdownFiles().filter(file => file.path.startsWith('Personal/Journal/'));
    console.log("Filtered files count: ", files.length); // Log how many files were filtered
    
    // Fetch metadata and store it properly with each file
    const filesWithMetadata = await Promise.all(files.map(async file => {
        const metadata = await this.app.vault.readStat(file.path);
        return { file, metadata }; // Return an object containing both the file and its metadata
    }));
    
    // Sort files based on the mtime found in metadata
    filesWithMetadata.sort((a, b) => a.metadata.stat.mtime - b.metadata.stat.mtime);

    // Extract the sorted files from the metadata wrapper
    const sortedFiles = filesWithMetadata.map(fwm => fwm.file);
    
    console.log("Sorted files: ", sortedFiles.map(f => f.path)); // Log sorted file paths

    // Find the index of the current file in the sorted array
    const currentFilePath = this.app.workspace.getActiveFile().path;
    const currentIndex = sortedFiles.findIndex(file => file.path === currentFilePath);
    
    console.log("Current file path: ", currentFilePath); // Log the current file path
    console.log("Current file index: ", currentIndex); // Log the index of current file

    const previousFile = currentIndex > 0 ? sortedFiles[currentIndex - 1] : null;
    const nextFile = currentIndex < sortedFiles.length - 1 ? sortedFiles[currentIndex + 1] : null;

    console.log("Previous file: ", previousFile ? previousFile.path : "None"); // Log previous file path
    console.log("Next file: ", nextFile ? nextFile.path : "None"); // Log next file path

    return {
        prevLink: previousFile ? `[[${previousFile.basename}|← Previous Journal]]` : '← Previous Journal (None)',
        nextLink: nextFile ? `[[${nextFile.basename}|Next Journal →]]` : 'Next Journal (None)'
    };
}

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.