From b437e8bb61f6a73a7ac0612ac58a8d97588a7893 Mon Sep 17 00:00:00 2001 From: Robert MacWha Date: Mon, 7 Oct 2024 16:24:22 -0400 Subject: [PATCH] feat: improved tag generation --- theme/tags_generator.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/theme/tags_generator.js b/theme/tags_generator.js index 4594f55..9be61df 100644 --- a/theme/tags_generator.js +++ b/theme/tags_generator.js @@ -75,9 +75,9 @@ function tagsGenerator(srcDir, outputDir) { } function generateColor(tag) { - const length = tag.length; - const hex = (length * 1234567).toString(16).slice(0, 6); - return `#${hex.padEnd(6, '0')}`; + const crypto = require("crypto"); + const hex = crypto.createHash("sha1").update(tag).digest("hex").slice(0, 6); + return `#${hex}`; } walkDir(srcDir); @@ -86,13 +86,18 @@ function tagsGenerator(srcDir, outputDir) { console.log(`Creating output directory: ${outputDir}`); fs.mkdirSync(outputDir, { recursive: true }); } - + console.log(`Writing tags to file: ${tagsFile}`); fs.writeFileSync(tagsFile, JSON.stringify(tags, null, 2)); - + + let existingColouredTags = {}; + if (fs.existsSync(colorsFile)) { + existingColouredTags = JSON.parse(fs.readFileSync(colorsFile, "utf8")); + } + const tagColors = {}; for (const tag in tags) { - tagColors[tag] = generateColor(tag); + tagColors[tag] = existingColouredTags[tag] || generateColor(tag); } console.log(`Writing tag colors to file: ${colorsFile}`);