---
import BaseHead from '../../components/BaseHead.astro';
import Footer from '../../components/Footer.astro';
import Header from '../../components/Header.astro';
import { SITE_DESCRIPTION, SITE_TITLE } from '../../consts';

import { getCollection } from 'astro:content';

const posts = (await getCollection('blog'))
  .filter((p) => !(((p.data as any).draft) ?? false))
  .sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf());
---

<!doctype html>
<html lang="en">
  <head>
    <BaseHead title="Blog | Sean's Cloud" description="Posts, lab notes, and lessons learned." />
  </head>
  <body>
    <Header />
    <main>
      <h1>Blog</h1>
      <p>Lab notes, guides, and lessons learned.</p>

      <ul>
        {posts.map((post) => (
          <li>
            <a href={`/blog/${post.id}/`}>{post.data.title}</a>
            <div>
              <small>{post.data.pubDate.toLocaleDateString()}</small>
              {post.data.description ? <p>{post.data.description}</p> : null}
            </div>
          </li>
        ))}
      </ul>
    </main>
    <Footer />
  </body>
</html>