feat: design + perf + tags etc.

This commit is contained in:
Cory Dransfeldt 2024-03-01 14:00:31 -08:00
parent 93f3506f83
commit 6c63611198
No known key found for this signature in database
44 changed files with 279 additions and 299 deletions

View file

@ -38,6 +38,23 @@ export const tagMap = (collection) => {
return tags
}
export const tagsSortedByCount = (collectionApi) => {
const tagStats = {};
const posts = collectionApi.getFilteredByGlob('src/posts/**/*.md').sort((a, b) => {
return a.date - b.date;
});
posts.forEach((post) => {
post.data.tags.forEach((tag) => {
if (!tagStats[tag]) tagStats[tag] = 1;
if (tagStats[tag]) tagStats[tag] = tagStats[tag] + 1;
});
});
const deletedTags = ['posts', 'politics', 'net neutrality'];
deletedTags.forEach(tag => delete tagStats[tag]);
const tagStatsArr = Object.entries(tagStats);
return tagStatsArr.sort((a, b) => b[1] - a[1]).map(([key, value]) => `${key}`);
}
export const postStats = (collectionApi) => {
const oneDayMilliseconds = 1000 * 60 * 60 * 24
const statsObject = {