• [#] #24/07 [^49eea990]

Main paragraph content

Blank container

Next paragraph content

  • [#] #24/07 [^9dd385e4]

Header2

Main paragraph content

Blank container

Next paragraph content

  • [#] #24/07 [^4a7e4374]

Main Article

Info

Addition note to the main article

Content of the main article

Transclude of Ontology-Diagram.canvas

  • [#] #24/07 [^33cb53ca]

Footer1

  • [#] #24/07 [^9a03ba69]

Footnotes

  • [#] #24/07 [^9f67a292]

Hashing Algorithm

<%* // Function to generate SHA-256 hash async function sha256(message) { const msgBuffer = new TextEncoder().encode(message); const hashBuffer = await crypto.subtle.digest(‘SHA-256’, msgBuffer); const hashArray = Array.from(new Uint8Array(hashBuffer)); return hashArray.map(b b.toString(16).padStart(2, ‘0’)).join(”); }

// Function to get the first 8 characters of a hash function getShortHash(hash) { return hash.substring(0, 8); }

// Function to remove footnotes function cleanContent(content) { return content.replace(/[^.*?]/g, ”); }

// Function to format header as an Obsidian internal link function formatHeaderLink(header) { return header.toLowerCase().replace(/[^\w\s-]/g, ”).replace(/\s+/g, ’-’); }

// Main processing function async function processDocument(content) { const lines = content.split(‘\n’); let processedContent = []; let currentBlock = []; let currentHeader = ”; let contentHashTable = {}; let footerContent = []; let isProcessingStarted = false; let isFooterReached = false;

const date = new Date();
const dateString = `${date.getFullYear().toString().substr(-2)}/${(date.getMonth() + 1).toString().padStart(2, '0')}`;

// Process the document line by line
for (const line of lines) {
    if (line.startsWith('#')) {
        // Process the previous block if it exists
        if (currentBlock.length > 0 && isProcessingStarted && !isFooterReached) {
            await processBlock(currentBlock, currentHeader, processedContent, contentHashTable, dateString);
        }

        currentHeader = line;
        currentBlock = [];
        isProcessingStarted = true;

        // Check if this is the Footer
        if (line.startsWith('# Footer')) {
            isFooterReached = true;
            footerContent.push(line);
            continue;
        }

        // Add the header to processed content
        processedContent.push(currentHeader);
    } else if (isFooterReached) {
        if (line.startsWith('## Content Hash Table')) {
            // Update Content Hash Table
            footerContent.push(line);
            for (const [contentHash, headerLink] of Object.entries(contentHashTable)) {
                footerContent.push(`[^${contentHash}]: [[${headerLink}]]`);
            }
            break; // Stop processing after updating the Content Hash Table
        } else {
            footerContent.push(line);
        }
    } else if (isProcessingStarted) {
        currentBlock.push(line);
    }
}

// Process the last block if it's not the Footer
if (currentBlock.length > 0 && !isFooterReached) {
    await processBlock(currentBlock, currentHeader, processedContent, contentHashTable, dateString);
}

// If no Footer was found, add it with the Content Hash Table
if (!isFooterReached) {
    footerContent.push('\n# Footer');
    footerContent.push('\n## Content Hash Table');
    for (const [contentHash, headerLink] of Object.entries(contentHashTable)) {
        footerContent.push(`[^${contentHash}]: [[${headerLink}]]`);
    }
}

// Combine all parts of the document
return processedContent.join('\n') + '\n\n' + footerContent.join('\n');

}

// Function to process a single block async function processBlock(block, header, processedContent, contentHashTable, dateString) { const headerHash = await sha256(header); const shortHeaderHash = getShortHash(headerHash);

// Find and remove the existing hash line, if present
let existingHashLine = null;
for (let i = block.length - 1; i >= 0; i--) {
    if (block[i].trim().startsWith('- [#]')) {
        existingHashLine = block.splice(i, 1)[0];
        break;
    }
}

const cleanedContent = cleanContent(block.join('\n'));
const contentHash = await sha256(cleanedContent);
const shortContentHash = getShortHash(contentHash);

// Store content hash and header link in the table
contentHashTable[shortContentHash] = formatHeaderLink(header);

// Add the processed block content to the result
processedContent.push(...block);

// Update or add the hash line
const hashLine = `- [#] #${dateString} [^${shortHeaderHash}] / [^${shortContentHash}]`;
if (existingHashLine) {
    // Replace the existing hash line
    processedContent.push(hashLine);
} else {
    // Add a new hash line
    processedContent.push(hashLine);
    processedContent.push(''); // Empty line for readability
}

}

// Main execution const originalContent = tp.file.content; const processedContent = await processDocument(originalContent); tR = processedContent; %>

Footnotes