aboutsummaryrefslogtreecommitdiff
path: root/src/pages/Blog.tsx
blob: fb07fb1d76fe703ee22e0e08cee796f944ebd789 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import Card from "../components/Card";

interface Meta {
  slug: string;
  title: string;
  date: string;
  excerpt: string;
  cover?: string;
}

const postFiles = import.meta.glob("../blog/*.md", { eager: true }) as Record<
  string,
  { attributes: Omit<Meta, "slug"> }
>;

const posts: Meta[] = Object.entries(postFiles)
  .map(([path, mod]) => ({
    slug: path.split("/").pop()!.replace(".md", ""),
    ...(mod.attributes as Omit<Meta, "slug">),
  }))
  .sort(
    (a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()
  );

export default function Blog() {
  return (
    <>
      <title>߸ projects</title>
      <h1>Blog</h1>
      
      {posts.map((post) => (
        <a key={post.slug} href={`/blog/${post.slug}`} className="block py-1">
          <Card
            title={post.title}
            body={post.excerpt}
            imgSrc={post.cover}
          />
        </a>
      ))}
    </>
  );
}