---
import {getCollection} from "astro:content";
import Layout from "../layouts/Layout.astro";
const allPosts = await getCollection('posts');
const uniqueCategories = [...new Set(allPosts.map((post: any) => post.data.categories ? post.data.categories : []).flat())];
---
<Layout title="Categoies" description="List all categories used in the blog posts.">
    <h1 class="title">~/blog/categories</h1>
    <div style="margin-top: 2rem;">
        <span class="command">ls -l categories/</span>
        <div style="margin-top: 1rem; margin-left: 1rem;">
            {uniqueCategories.map((tag) => (
                    <p><a href={`/categories/${tag}`}>{tag}</a></p>
            ))}
        </div>
    </div>
</Layout>
