---
import BaseLayout from "../layouts/BaseLayout.astro";
import { getCollection, getEntry } from "astro:content";

const pageTitle = "blog";
const posts = await getCollection("posts");
console.log(posts);
const allPosts = Object.values(
    import.meta.glob("./posts/*.{md,mdx}", { eager: true }),
);
allPosts.sort(
    (a, b) => new Date(b.frontmatter.pubDate) - new Date(a.frontmatter.pubDate),
);
---

<BaseLayout pageTitle={pageTitle}>
    <p>
        ITT: the incoherent ramblings of a fatigued madman with a technological
        inclination.
    </p>

    <hr />

    <div style="text-align: left;">
        <h2>posts</h2>
        <ul style="line-height: 1.8;">
            {
                allPosts.map((post: any) => (
                    <li>
                        <a href={post.url}>{post.frontmatter.title.length > 50
                                ? `${post.frontmatter.title.substring(0, 50)}…`
                                : post.frontmatter.title}</a>
                        —
                        <em>
                            published on{" "}
                            {post.frontmatter.pubDate.toString().slice(0, 10)}
                        </em>
                    </li>
                ))
            }
        </ul>
    </div>
</BaseLayout>
