-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeystatic.config.ts
More file actions
190 lines (185 loc) · 6.09 KB
/
Copy pathkeystatic.config.ts
File metadata and controls
190 lines (185 loc) · 6.09 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import { collection, config, fields } from "@keystatic/core";
const isGitHubStorage =
process.env.NEXT_PUBLIC_KEYSTATIC_STORAGE_KIND === "github" ||
Boolean(process.env.NEXT_PUBLIC_KEYSTATIC_GITHUB_APP_SLUG);
const categoryOptions = [
"Announcement",
"Defense",
"Education",
"Presentation",
"Publication",
"Social",
"Travel",
"Video",
].map((category) => ({ label: category, value: category }));
function sanitizeAssetFilename(originalFilename: string): string {
const extensionIndex = originalFilename.lastIndexOf(".");
const hasExtension = extensionIndex > 0;
const basename = hasExtension
? originalFilename.slice(0, extensionIndex)
: originalFilename;
const extension = hasExtension
? originalFilename.slice(extensionIndex).toLowerCase()
: "";
const safeBasename = basename
.normalize("NFKD")
.replace(/[\u0300-\u036f]/g, "")
.toLowerCase()
.replace(/[^a-z0-9]+/g, "-")
.replace(/^-+|-+$/g, "");
return `${safeBasename || "image"}${extension}`;
}
export default config({
storage: isGitHubStorage
? {
kind: "github",
repo: "PreferredAI/PreferredAI.github.io",
branchPrefix: "keystatic/",
}
: {
kind: "local",
},
ui: {
brand: { name: "Preferred.AI Publisher" },
navigation: ["posts", "people"],
},
collections: {
posts: collection({
label: "Posts",
slugField: "title",
path: "content/posts/*",
format: { contentField: "content" },
entryLayout: "content",
columns: ["title", "date", "author"],
previewUrl: "/blog/{slug}",
schema: {
title: fields.slug({
name: {
label: "Title",
validation: { isRequired: true },
},
}),
date: fields.date({
label: "Publish date",
defaultValue: { kind: "today" },
validation: { isRequired: true },
}),
author: fields.text({
label: "Author",
defaultValue: "Preferred.AI",
validation: { isRequired: true },
}),
excerpt: fields.text({
label: "Excerpt",
multiline: true,
description:
"A one or two sentence summary used in post listings and as the default SEO description.",
validation: { isRequired: true },
}),
cover: fields.image({
label: "Featured image",
description:
"Choose or drop an image. Keystatic stores it in public/uploads/<post-slug>/cover.<ext>.",
directory: "public/uploads",
publicPath: "/uploads",
}),
featuredImage: fields.text({
label: "Existing featured image path (legacy)",
description:
"Existing posts may use an /uploads/YYYY/MM/... path. Leave this empty for new posts and use the image picker above.",
}),
categories: fields.multiselect({
label: "Categories",
description: "Choose every category that applies.",
options: categoryOptions,
defaultValue: ["Education"],
}),
tags: fields.array(fields.text({ label: "Tag" }), {
label: "Tags",
description: "Optional keywords for this post.",
itemLabel: (props) => props.value,
}),
seoTitle: fields.text({
label: "SEO Title",
description: "Optional. Defaults to the post title when left empty.",
}),
seoDescription: fields.text({
label: "SEO Description",
multiline: true,
description: "Optional. Defaults to the excerpt when left empty.",
}),
content: fields.markdoc({
label: "Content",
description:
"Use the image toolbar button, paste, or drag and drop. Add meaningful alt text when prompted. Write inline math as $...$ and display math as $$...$$.",
extension: "md",
options: {
image: {
directory: "public/uploads",
publicPath: "/uploads",
transformFilename: sanitizeAssetFilename,
},
},
}),
},
}),
people: collection({
label: "People",
slugField: "name",
path: "content/people/*",
format: "json",
entryLayout: "form",
columns: ["name", "placement", "title"],
previewUrl: "/people",
schema: {
name: fields.slug({
name: {
label: "Name",
validation: { isRequired: true },
},
slug: {
label: "URL-safe slug",
description:
"Lowercase letters, numbers, and hyphens. This also names the profile photo folder.",
validation: {
pattern: {
regex: /^[a-z0-9]+(?:-[a-z0-9]+)*$/,
message:
"Use lowercase letters, numbers, and single hyphens only.",
},
},
},
}),
placement: fields.select({
label: "Placement",
description: "Controls the section and ordering on the People page.",
options: [
{ label: "Professor", value: "professor" },
{ label: "Research Staff", value: "research-staff" },
{ label: "PhD Candidate", value: "phd-candidate" },
{ label: "PhD Co-supervisee", value: "phd-co-supervisee" },
{ label: "Alumni", value: "alumni" },
],
defaultValue: "phd-candidate",
}),
photo: fields.image({
label: "Profile photo",
description:
"Choose or drop a JPG, PNG, or WebP image. Keystatic stores it in public/team/members/<person-slug>/photo.<ext>.",
directory: "public/team/members",
publicPath: "/team/members/",
validation: { isRequired: true },
}),
title: fields.text({
label: "Position or title",
description:
"Optional, including for alumni without a current title.",
}),
url: fields.url({
label: "Personal or professional URL",
description: "Optional. Include https:// or http://.",
}),
},
}),
},
});