aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/blog/Post.ts
blob: aa4c4229e99609dcc53fc155d69fab724e658cf3 (plain) (blame)
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
import type { Component } from 'svelte';

export type PostMetadata<Parsed extends boolean = false> = {
  title: string;
  blurb: string;
  author: string | null;
  slug: string;
  id: string | number;
  created: Parsed extends true ? Date : string;
  updated: Parsed extends true ? Date : string;
  published: boolean | 'unlisted';
};
export type Post<MetadataParsed extends boolean = false> = {
  metadata: PostMetadata<MetadataParsed>;
  default: Component;
};

export const parsePostMetadata = (
  m: PostMetadata<boolean>,
): PostMetadata<true> => ({
  ...m,
  created: new Date(m.created),
  updated: new Date(m.updated),
});
export const parsePost = (p: Post<boolean>): Post<true> => ({
  ...p,
  metadata: parsePostMetadata(p.metadata),
});