aliases: 2024-09-24

DS Tagger Chain 5.2 | digested 2024-09-24

[[{currentDate}

${cleanBlock}`; await upsertToFile(blockFilePath, ’# ’, blockFileContent); }

    let result = processedBlocks.join('\n\n');

    // Create file seal hash
    let fileSealHash = createFileSealHash(result);
    console.log(`\n[${currentDate}] File seal hash created: ${fileSealHash}`);

    // Add file seal hash and timestamp to frontmatter
    let frontmatter = content.match(/^---\n[\s\S]*?\n---\n/);
    const fileSealTimestamp = new Date().toISOString();
    if (frontmatter) {
        let updatedFrontmatter = frontmatter[0]
            .replace(/file-seal-hash:.*\n/, '')
            .replace(/file-seal-timestamp:.*\n/, '');
        updatedFrontmatter = updatedFrontmatter.replace(/---\n$/, `file-seal-hash: "${fileSealHash}"\nfile-seal-timestamp: "${fileSealTimestamp}"\n---\n`);
        result = updatedFrontmatter + result;
    } else {
        result = `---\nfile-seal-hash: "${fileSealHash}"\nfile-seal-timestamp: "${fileSealTimestamp}"\n---\n\n${result}`;
    }

    // Write chain entry
    const chainFilePath = `Notes/ds/chains/${currentDate.substring(0, 7)}.md`;
    const chainEntry = createChainEntry(fileName, fileSealHash, digestTags, currentTimestamp);
    try {
        await upsertToFile(chainFilePath, `### [[${fileName}]]`, chainEntry);
        new Notice(`Chain entry written successfully to ${chainFilePath}`, 10000);
    } catch (error) {
        new Notice(`Failed to write chain entry: ${error.message}`, 10000);
        console.error('Failed to write chain entry:', error);
    }

    // Update the file content using app.vault.modify
    await app.vault.modify(tp.file.find_tfile(tp.file.title), result);

    const endTime = Date.now();
    const runtime = ((endTime - startTime) / 1000).toFixed(2);
    console.log(`\n[${currentDate}] DS Tagger Chain process completed successfully`);
    new Notice(`DS Tagger Chain v${version} completed:

Runtime: {fileSealHash} Blocks processed: {digestedBlocks} Blocks not digested: {updatedBlocks} Date: ${currentDate}`, 10000);

} catch (error) {
    console.error(`[${currentDate}] An error occurred:`, error);
    new Notice(`Error: ${error.message}. Check console for details.`, 10000);
}

}

// Run the script and output the result await dsTaggerChain(); %>