Skip to content

Instantly share code, notes, and snippets.

@mutoo
Created December 27, 2019 13:11
Show Gist options
  • Save mutoo/b82b3a05b5247d033e5b143bb7114763 to your computer and use it in GitHub Desktop.
Save mutoo/b82b3a05b5247d033e5b143bb7114763 to your computer and use it in GitHub Desktop.
Report the tags conflict in your posts. Just put this script in the /scrips/ folder, and it would ran everytime the post being edited.
hexo.extend.generator.register('posts', function(locals) {
const tagMap = {};
// first pass collect all tags in lower cases
const posts = locals.posts;
posts.forEach(post => {
post.tags.forEach(({ name }) => {
const lowercase = name.toLowerCase();
if (!tagMap[lowercase]) tagMap[lowercase] = {};
tagMap[lowercase][name] = (tagMap[lowercase][name] || 0) + 1;
});
});
// second pass check all tags with cases conflict
Object.values(tagMap).forEach(group => {
const keys = Object.keys(group);
if (keys.length > 1) {
console.warn(`tags conflict: ${keys.join(', ')}`);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment