feat: add wordcount heatmap

This commit is contained in:
草师傅 2025-08-06 19:04:29 +08:00
parent 8773b9b0df
commit b79e3e2e47
Signed by: gb
GPG key ID: 43330A030E2D6478
9 changed files with 351 additions and 1 deletions

View file

@ -0,0 +1,30 @@
import { getCollection, render } from 'astro:content';
async function fetchPostsData() {
const posts = await getCollection('posts');
const entriesData = {};
for (const post of posts) {
const { remarkPluginFrontmatter } = await post.render();
const dateKey = post.data.pubDate.toISOString().split('T')[0]; // "2025-07-25"
entriesData[dateKey] = {
wordCount: remarkPluginFrontmatter.wordcount.words / 1000 || 0,
link: `/blog/${post.slug}`,
title: post.data.title
};
}
return entriesData;
}
export async function generateLocalData() {
const postsData = await fetchPostsData();
const data = []
Object.entries(postsData).forEach(([dateKey, entry]) => {
data.push([
new Date(dateKey).toISOString().split('T')[0], // Convert to YYYY-MM-DD format
entry.wordCount || 0,
])
})
return data;
}