aliases: 2024-09-24 file-seal-hash: cd554063c1fc

DS Tagger Chain 7.5 | digested 2024-09-24

[[{currentDate}

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

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

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

    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}`;
    }

    const chainFilePath = `Notes/ds/chains/${currentDate.substring(0, 7)}.md`;
    let previousBlockchainEntryDigest = '';
    const chainFile = app.vault.getAbstractFileByPath(chainFilePath);
    
    if (chainFile) {
        const chainFileContent = await app.vault.read(chainFile);
        const lastEntryMatch = chainFileContent.match(/#ds\/([a-f0-9]+)$/m);
        previousBlockchainEntryDigest = lastEntryMatch ? lastEntryMatch[1] : '';
    } else {
        previousBlockchainEntryDigest = generateHash(currentDate.substring(0, 7));
    }

    const chainEntry = createChainEntry(fileName, fileSealHash, digestTags, currentTimestamp, previousBlockchainEntryDigest);
    try {
        await upsertToFile(chainFilePath, `### [[${fileName}]]`, chainEntry);
        
        // Extract the new blockchain entry digest from the chain entry
        const newBlockchainEntryDigest = chainEntry.match(/#ds\/([a-f0-9]+)$/)[1];
        
        new Notice(`Blockchain entry created successfully:

${chainEntry}

New blockchain entry digest: {newBlockchainEntryDigest}`, 10000); } catch (error) { new Notice(`Failed to write chain entry: {error.message}`, 10000); console.error(‘Failed to write chain entry:’, error); }

    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(); %>