packages/cli/src/lib/types.ts 3.9 K raw
1
export interface FrontmatterMapping {
2
	title?: string; // Field name for title (default: "title")
3
	description?: string; // Field name for description (default: "description")
4
	publishDate?: string; // Field name for publish date (default: "publishDate", also checks "pubDate", "date", "createdAt", "created_at")
5
	coverImage?: string; // Field name for cover image (default: "ogImage")
6
	tags?: string; // Field name for tags (default: "tags")
7
	draft?: string; // Field name for draft status (default: "draft")
8
	slugField?: string; // Frontmatter field to use for slug (if set, uses frontmatter value; otherwise uses filepath)
9
}
10
11
// Strong reference for Bluesky post (com.atproto.repo.strongRef)
12
export interface StrongRef {
13
	uri: string; // at:// URI format
14
	cid: string; // Content ID
15
}
16
17
// Bluesky posting configuration
18
export interface BlueskyConfig {
19
	enabled: boolean;
20
	maxAgeDays?: number; // Only post if published within N days (default: 7)
21
}
22
23
export interface PublisherConfig {
24
	siteUrl: string;
25
	contentDir: string;
26
	imagesDir?: string; // Directory containing cover images
27
	publicDir?: string; // Static/public folder for .well-known files (default: public)
28
	outputDir?: string; // Built output directory for inject command
29
	pathPrefix?: string; // URL path prefix for posts (default: /posts)
30
	publicationUri: string;
31
	pdsUrl?: string;
32
	identity?: string; // Which stored identity to use (matches identifier)
33
	frontmatter?: FrontmatterMapping; // Custom frontmatter field mappings
34
	ignore?: string[]; // Glob patterns for files to ignore (e.g., ["_index.md", "**/drafts/**"])
35
	removeIndexFromSlug?: boolean; // Remove "/index" or "/_index" suffix from paths (default: false)
36
	stripDatePrefix?: boolean; // Remove YYYY-MM-DD- prefix from filenames (Jekyll-style, default: false)
37
	textContentField?: string; // Frontmatter field to use for textContent instead of markdown body
38
	bluesky?: BlueskyConfig; // Optional Bluesky posting configuration
39
}
40
41
// Legacy credentials format (for backward compatibility during migration)
42
export interface LegacyCredentials {
43
	pdsUrl: string;
44
	identifier: string;
45
	password: string;
46
}
47
48
// App password credentials (explicit type)
49
export interface AppPasswordCredentials {
50
	type: "app-password";
51
	pdsUrl: string;
52
	identifier: string;
53
	password: string;
54
}
55
56
// OAuth credentials (references stored OAuth session)
57
// Note: pdsUrl is not needed for OAuth - the OAuth client resolves PDS from the DID
58
export interface OAuthCredentials {
59
	type: "oauth";
60
	did: string;
61
	handle: string;
62
}
63
64
// Union type for all credential types
65
export type Credentials = AppPasswordCredentials | OAuthCredentials;
66
67
// Helper to check credential type
68
export function isOAuthCredentials(
69
	creds: Credentials,
70
): creds is OAuthCredentials {
71
	return creds.type === "oauth";
72
}
73
74
export function isAppPasswordCredentials(
75
	creds: Credentials,
76
): creds is AppPasswordCredentials {
77
	return creds.type === "app-password";
78
}
79
80
export interface PostFrontmatter {
81
	title: string;
82
	description?: string;
83
	publishDate: string;
84
	tags?: string[];
85
	ogImage?: string;
86
	atUri?: string;
87
	draft?: boolean;
88
}
89
90
export interface BlogPost {
91
	filePath: string;
92
	slug: string;
93
	frontmatter: PostFrontmatter;
94
	content: string;
95
	rawContent: string;
96
	rawFrontmatter: Record<string, unknown>; // For accessing custom fields like textContentField
97
}
98
99
export interface BlobRef {
100
	$link: string;
101
}
102
103
export interface BlobObject {
104
	$type: "blob";
105
	ref: BlobRef;
106
	mimeType: string;
107
	size: number;
108
}
109
110
export interface PublisherState {
111
	posts: Record<string, PostState>;
112
}
113
114
export interface PostState {
115
	contentHash: string;
116
	atUri?: string;
117
	lastPublished?: string;
118
	slug?: string; // The generated slug for this post (used by inject command)
119
	bskyPostRef?: StrongRef; // Reference to corresponding Bluesky post
120
}
121
122
export interface PublicationRecord {
123
	$type: "site.standard.publication";
124
	url: string;
125
	name: string;
126
	description?: string;
127
	icon?: BlobObject;
128
	createdAt: string;
129
	preferences?: {
130
		showInDiscover?: boolean;
131
	};
132
}