summaryrefslogtreecommitdiff
path: root/src/lib/components/PostCard.svelte
blob: 83ae71d4831b937cc8a90144ac6a7d3a368538e5 (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
<script lang="ts">
  import type { Post } from "$lib/utils/posts";

  interface Props {
    post: Post;
  }

  let { post }: Props = $props();

  function formatDate(dateStr: string): string {
    return new Date(dateStr).toLocaleDateString("en-US", {
      year: "numeric",
      month: "long",
      day: "numeric",
    });
  }
</script>

<article>
  <header>
    <a href="/posts/{post.slug}">
      <h1 style="text-decoration: none;">{post.title}</h1>
    </a>
    <small><time datetime={post.date}>{formatDate(post.date)}</time></small>
  </header>
  <p>{post.description}</p>
</article>