-
-
Notifications
You must be signed in to change notification settings - Fork 424
Expand file tree
/
Copy pathblog.ts
More file actions
73 lines (65 loc) · 1.82 KB
/
blog.ts
File metadata and controls
73 lines (65 loc) · 1.82 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import {
array,
boolean,
custom,
isoTimestamp,
nullable,
object,
optional,
pipe,
string,
} from 'valibot'
import { isAtIdentifierString, type AtIdentifierString } from '@atproto/lex'
import type { InferOutput } from 'valibot'
export const AuthorSchema = object({
name: string(),
blueskyHandle: optional(
pipe(
string(),
custom<AtIdentifierString>(v => typeof v === 'string' && isAtIdentifierString(v)),
),
),
})
export const ResolvedAuthorSchema = object({
name: string(),
blueskyHandle: optional(
pipe(
string(),
custom<AtIdentifierString>(v => typeof v === 'string' && isAtIdentifierString(v)),
),
),
avatar: nullable(string()),
profileUrl: nullable(string()),
})
/** Schema for raw frontmatter as defined in markdown YAML */
export const RawBlogPostSchema = object({
authors: array(AuthorSchema),
title: string(),
date: pipe(string(), isoTimestamp()),
description: string(),
path: string(),
slug: string(),
excerpt: optional(string()),
tags: optional(array(string())),
draft: optional(boolean()),
})
/** Schema for blog post frontmatter with resolved author data (avatars, profile URLs) */
export const BlogPostSchema = object({
authors: array(ResolvedAuthorSchema),
title: string(),
date: pipe(string(), isoTimestamp()),
description: string(),
path: string(),
slug: string(),
excerpt: optional(string()),
tags: optional(array(string())),
draft: optional(boolean()),
})
export type Author = InferOutput<typeof AuthorSchema>
export type ResolvedAuthor = InferOutput<typeof ResolvedAuthorSchema>
/** Raw frontmatter type (before avatar resolution) */
export type RawBlogPostFrontmatter = InferOutput<typeof RawBlogPostSchema>
/**
* Inferred type for blog post frontmatter
*/
export type BlogPostFrontmatter = InferOutput<typeof BlogPostSchema>