Next Week: 2024-W32 Previous Week: 2024-W30
Days in the Week:
S 28 • M 29 • T 30 • W 31 • T 01 • F 02 • S 03
<%* const crypto = require(‘crypto’);
// Function to calculate SHA-256 hash and return the first 8 characters function calculateHash(content) { return crypto.createHash(‘sha256’).update(content).digest(‘hex’).slice(0, 8); }
// Get the current date in YYMMDD format
function getCurrentDate() {
const date = new Date();
const yy = String(date.getFullYear()).slice(-2);
const mm = String(date.getMonth() + 1).padStart(2, ‘0’);
const dd = String(date.getDate()).padStart(2, ‘0’);
return ${yy}${mm}${dd};
}
// Read the file content const content = tp.file.content;
// Split the content into lines const lines = content.split(‘\n’);
// Find the index of the function call const functionCallIndex = lines.findIndex(line ⇒ line.includes(’<% tp.user.Above_Hasher() %>’));
// Get the content above the function call const contentAbove = lines.slice(0, functionCallIndex).join(‘\n’);
// Filter out lines that start with ”- [@] 🅦 WikiWe.org hash” const filteredContent = contentAbove.split(‘\n’).filter(line ⇒ !line.startsWith(’- [@] 🅦 WikiWe.org hash’)).join(‘\n’);
// Calculate the hash of the filtered content const hash = calculateHash(filteredContent);
// Get the current date const currentDate = getCurrentDate();
// Format the output
const output = - [@] [[🅦 WikiWe.org]] #hash/ab/${hash}-${currentDate};
// Check if the output already exists in the file const outputExists = lines.some(line ⇒ line.includes(output));
// If the output doesn’t exist, append it to the file if (!outputExists) { tR += output; } %>