// src/content/posts/example-post.md
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent porttitor posuere est. Morbi facilisis, felis vitae rutrum luctus, risus orci congue nulla, non rhoncus justo neque non est
--- | |
export const prerender = true; | |
import { getCollection } from 'astro:content'; | |
import RadarChart from '../components/radar-chart.astro'; | |
const posts = await getCollection('posts', ({ data }) => { | |
const { tags } = data; | |
if (Array.isArray(tags) && tags.length > 0) return data; | |
}); | |
const groupByTag = (array) => { | |
return Object.values( | |
array.reduce((acc, item) => { | |
const { tags } = item.data; | |
tags.forEach((tag) => { | |
if (!acc[tag]) { | |
acc[tag] = { | |
name: tag, | |
total: 0, | |
}; | |
} | |
acc[tag].total++; | |
}); | |
return acc; | |
}, {}) | |
); | |
}; | |
const data = groupByTag(posts); | |
--- | |
<main class=''> | |
<RadarChart data={data} /> | |
</main> |