Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Tag Generation #79

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions theme/tags_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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}`);
Expand Down
Loading