---
import BaseLayout from '../layouts/BaseLayout.astro';
import EntryList from '../components/EntryList.astro';
import { getAllEntries } from '../lib/entries';
import {
  buildOgImage,
  buildBreadcrumbs,
  buildItemList,
  absoluteUrl,
} from '../lib/seo';

const posts = (await getAllEntries()).filter((e) => e.type === 'post');
const lastUpdated = posts[0]?.date;

const description = 'Longer-form notes from Unique — essays and meta about the project.';
const ogImage = buildOgImage(undefined, 'posts', 'Unique blog');

const itemList = buildItemList(
  posts.map((p) => ({ url: p.href, name: p.primary })),
  'Posts on Unique'
);

const blogSchema: Record<string, unknown> = {
  '@context': 'https://schema.org',
  '@type': 'Blog',
  '@id': absoluteUrl('/blog/#blog'),
  name: 'Unique — Blog',
  description,
  url: absoluteUrl('/blog/'),
  inLanguage: 'en-US',
};

const breadcrumbs = buildBreadcrumbs([
  { name: 'Home', url: '/' },
  { name: 'Blog', url: '/blog/' },
]);
---

<BaseLayout
  title="Blog"
  description={description}
  subheader="Longer notes, when something deserves more than a card."
  lastUpdated={lastUpdated}
  ogImage={ogImage}
  jsonLd={[blogSchema, itemList, breadcrumbs]}
>
  {posts.length > 0 ? (
    <EntryList entries={posts} />
  ) : (
    <p class="empty">Nothing yet — check back soon.</p>
  )}

  <style>
    .empty {
      margin: 3rem 0;
      text-align: center;
      color: var(--muted);
      font-style: italic;
    }
  </style>
</BaseLayout>
