---
import { getCollection } from 'astro:content';
import SiteLayout from '../../components/SiteLayout.astro';

/* Drafts render locally and never in a build, so an unpublished post can be
   reviewed on the dev server without being one deploy away from going live. */
const posts = (await getCollection('blog'))
  .filter((post) => import.meta.env.DEV || !post.data.draft)
  .map((post) => ({ ...post, slug: post.id.replace(/\.(md|mdx)$/i, '') }))
  .sort((a, b) => b.data.date.valueOf() - a.data.date.valueOf());

const stamp = (date) =>
  date.toLocaleDateString('en', { year: 'numeric', month: 'short', day: 'numeric' });
---

<SiteLayout
  title="Herdr blog"
  description="Notes on the agent runtime — product decisions, implementation writeups, and what we learned running agents on machines nobody is watching."
  canonicalPath="/blog/"
>
  <header class="ph">
    <div class="hd-eyebrow"><s></s>the blog</div>
    <h1>Notes from the herd.</h1>
    <p>
      Product decisions, implementation writeups, and what we learn running agents on
      machines nobody is watching.
    </p>
  </header>

  <div class="posts">
    {posts.map((post) => (
      <a href={`/blog/${post.slug}/`}>
        <time datetime={post.data.date.toISOString()}>{stamp(post.data.date)}</time>
        <div>
          <h2>{post.data.title}</h2>
          {post.data.description && <p>{post.data.description}</p>}
        </div>
        <span class="go-arrow" aria-hidden="true">→</span>
      </a>
    ))}
  </div>
</SiteLayout>
