Skip to content

Commit 93f02f7

Browse files
committed
feat(keystatic): add featured post toggle, relocate assistant box to bottom-left, and support unquoted dates
1 parent be61312 commit 93f02f7

10 files changed

Lines changed: 214 additions & 32 deletions

File tree

‎apps/admin/keystatic.config.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ export function createKeystaticConfig(sortRanks?: CollectionSortRanks) {
117117
directory: "public/uploads",
118118
publicPath: "/uploads/",
119119
}),
120+
featured: fields.checkbox({
121+
label: "Featured post (Pin to Homepage hero)",
122+
description:
123+
"Check to pin this post in the main Featured spot at the top of the homepage. If unchecked, the newest post is featured automatically.",
124+
defaultValue: false,
125+
}),
120126
featuredImage: fields.text({
121127
label: "Legacy image path (leave empty for new posts)",
122128
description:

‎apps/admin/src/app/keystatic/workflow-assistant.tsx‎

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,27 @@ export default function KeystaticWorkflowAssistant() {
143143
const [status, setStatus] = useState<BranchStatus | null>(null);
144144
const [busyAction, setBusyAction] = useState<string | null>(null);
145145
const [errorMsg, setErrorMsg] = useState<string | null>(null);
146-
const [collapsed, setCollapsed] = useState<boolean>(false);
146+
const [collapsed, setCollapsed] = useState<boolean>(() => {
147+
if (typeof window !== "undefined") {
148+
try {
149+
return localStorage.getItem("ks-assistant-collapsed") === "true";
150+
} catch {
151+
return false;
152+
}
153+
}
154+
return false;
155+
});
156+
157+
const toggleCollapsed = useCallback((nextCollapsed: boolean) => {
158+
setCollapsed(nextCollapsed);
159+
if (typeof window !== "undefined") {
160+
try {
161+
localStorage.setItem("ks-assistant-collapsed", String(nextCollapsed));
162+
} catch {
163+
// ignore localStorage errors
164+
}
165+
}
166+
}, []);
147167

148168
useEffect(() => {
149169
const syncLocationAndCookie = () => {
@@ -429,15 +449,15 @@ export default function KeystaticWorkflowAssistant() {
429449
<div
430450
style={{
431451
position: "fixed",
432-
right: 16,
452+
left: 16,
433453
bottom: 16,
434454
zIndex: 9999,
435455
fontFamily:
436456
'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
437457
}}
438458
>
439459
<button
440-
onClick={() => setCollapsed(false)}
460+
onClick={() => toggleCollapsed(false)}
441461
style={{
442462
background: "#18181b",
443463
color: "#fafafa",
@@ -467,7 +487,7 @@ export default function KeystaticWorkflowAssistant() {
467487
<div
468488
style={{
469489
position: "fixed",
470-
right: 16,
490+
left: 16,
471491
bottom: 16,
472492
zIndex: 9999,
473493
maxWidth: 440,
@@ -526,7 +546,7 @@ export default function KeystaticWorkflowAssistant() {
526546
</button>
527547
)}
528548
<button
529-
onClick={() => setCollapsed(true)}
549+
onClick={() => toggleCollapsed(true)}
530550
title="Minimize helper"
531551
style={{
532552
background: "transparent",

‎scripts/check-editorial-content.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const allowedPostKeys = new Set([
1919
"excerpt",
2020
"cover",
2121
"featuredImage",
22+
"featured",
2223
"categories",
2324
"tags",
2425
"seoTitle",
@@ -42,6 +43,17 @@ const dangerousMarkdown = [
4243
const angleWrappedMediaReference = /<((?:\/uploads|\/team\/members)\/[^>]+)>/gu;
4344
const localMediaReference = /\/(?:uploads|team\/members)\/[^)\]}\s"'<>]+/gu;
4445

46+
function parseDateValue(value: unknown): string | null {
47+
if (value instanceof Date && !Number.isNaN(value.getTime())) {
48+
return value.toISOString().slice(0, 10);
49+
}
50+
if (typeof value === "string") {
51+
const trimmed = value.trim();
52+
if (trimmed.length > 0) return trimmed;
53+
}
54+
return null;
55+
}
56+
4557
function requiredString(
4658
data: Record<string, unknown>,
4759
key: string,
@@ -131,11 +143,15 @@ function validatePost(filename: string): number {
131143
requiredString(data, "title", filename);
132144
requiredString(data, "author", filename);
133145
requiredString(data, "excerpt", filename);
134-
const date = requiredString(data, "date", filename);
135-
if (!isRealDate(date)) {
146+
const date = parseDateValue(data.date);
147+
if (!date || !isRealDate(date)) {
136148
throw new Error(`${filename}: date must be a real YYYY-MM-DD date`);
137149
}
138150

151+
if (data.featured !== undefined && typeof data.featured !== "boolean") {
152+
throw new Error(`${filename}: featured must be a boolean`);
153+
}
154+
139155
const rawFeaturedImage =
140156
typeof data.cover === "string" ? data.cover : data.featuredImage;
141157
const featuredImage =

‎scripts/generate-posts-index.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface MarkdownPost {
1717
author: string;
1818
excerpt: string;
1919
featuredImage: string;
20+
featured?: boolean;
2021
categories: string[];
2122
tags: string[];
2223
seoTitle: string;
@@ -28,6 +29,13 @@ function trimStr(value: unknown): string {
2829
return typeof value === "string" ? value.trim() : "";
2930
}
3031

32+
function parsePostDate(value: unknown): string {
33+
if (value instanceof Date && !Number.isNaN(value.getTime())) {
34+
return value.toISOString().slice(0, 10);
35+
}
36+
return typeof value === "string" ? value.trim() : "";
37+
}
38+
3139
export function buildPostsIndex(): MarkdownPost[] {
3240
if (!fs.existsSync(postsDirectory)) {
3341
throw new Error(`Missing posts directory: ${postsDirectory}`);
@@ -51,10 +59,11 @@ export function buildPostsIndex(): MarkdownPost[] {
5159
return {
5260
slug,
5361
title,
54-
date: trimStr(data.date),
62+
date: parsePostDate(data.date),
5563
author: trimStr(data.author),
5664
excerpt,
5765
featuredImage: trimStr(data.cover) || trimStr(data.featuredImage),
66+
featured: Boolean(data.featured),
5867
categories: Array.isArray(data.categories)
5968
? data.categories.map(trimStr).filter(Boolean)
6069
: [],

‎src/app/(site)/page.tsx‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import { FeaturedPostCard } from "@/components/FeaturedPostCard";
44
import Pagination from "@/components/Pagination";
55
import { PostCard } from "@/components/PostCard";
66
import TeamPhotos from "@/components/TeamPhotos";
7-
import { getAllPosts } from "@/lib/markdown-posts";
7+
import { getAllPosts, getFeaturedPost } from "@/lib/markdown-posts";
88

99
export default async function Home() {
10-
const { posts, pages } = await getAllPosts(1, 12, { firstPageLimit: 10 });
11-
12-
const featuredPost = posts[0];
13-
const remainingPosts = posts.slice(1);
10+
const featuredPost = getFeaturedPost();
11+
const { posts: remainingPosts, pages } = await getAllPosts(1, 12, {
12+
firstPageLimit: 9,
13+
excludeSlug: featuredPost?.slug,
14+
});
1415

1516
return (
1617
<div>
@@ -34,7 +35,9 @@ export default async function Home() {
3435
</div>
3536
)}
3637

37-
{posts.length > 0 && <CategoryFilterBar allHref="/" className="mb-6" />}
38+
{(featuredPost || remainingPosts.length > 0) && (
39+
<CategoryFilterBar allHref="/" className="mb-6" />
40+
)}
3841

3942
{remainingPosts.length > 0 && (
4043
<div className="feed-grid grid gap-5 sm:gap-6 md:grid-cols-2 lg:grid-cols-3">
@@ -44,7 +47,7 @@ export default async function Home() {
4447
</div>
4548
)}
4649

47-
{posts.length === 0 && (
50+
{!featuredPost && remainingPosts.length === 0 && (
4851
<div className="rounded-3xl border border-border/70 bg-card/85 px-6 py-16 text-center">
4952
<p className="text-lg font-extrabold text-foreground">No posts yet</p>
5053
<p className="mx-auto mt-2 max-w-md text-pretty text-muted-foreground">

‎src/app/(site)/page/[page]/page.tsx‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { notFound } from "next/navigation";
33
import CategoryFilterBar from "@/components/CategoryFilterBar";
44
import Pagination from "@/components/Pagination";
55
import { PostCard } from "@/components/PostCard";
6-
import { getAllPosts } from "@/lib/markdown-posts";
6+
import { getAllPosts, getFeaturedPost } from "@/lib/markdown-posts";
77

88
interface PageProps {
99
params: Promise<{
@@ -31,8 +31,10 @@ export default async function PaginatedHomePage({ params }: PageProps) {
3131
notFound();
3232
}
3333

34+
const featuredPost = getFeaturedPost();
3435
const { posts, pages } = await getAllPosts(currentPage, 12, {
35-
firstPageLimit: 10,
36+
firstPageLimit: 9,
37+
excludeSlug: featuredPost?.slug,
3638
});
3739

3840
if (currentPage > pages) {
@@ -70,7 +72,11 @@ export default async function PaginatedHomePage({ params }: PageProps) {
7072
}
7173

7274
export async function generateStaticParams() {
73-
const { pages } = await getAllPosts(1, 12, { firstPageLimit: 10 });
75+
const featuredPost = getFeaturedPost();
76+
const { pages } = await getAllPosts(1, 12, {
77+
firstPageLimit: 9,
78+
excludeSlug: featuredPost?.slug,
79+
});
7480
if (pages <= 1) return [];
7581

7682
return Array.from({ length: pages - 1 }, (_, i) => ({

‎src/data/generated-image-manifest.json‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,6 +1653,22 @@
16531653
"sourceWidth": 450,
16541654
"sourceHeight": 450
16551655
},
1656+
"/uploads/disentangling-preferences/chimichanga.jpg": {
1657+
"sourceWidth": 1280,
1658+
"sourceHeight": 719
1659+
},
1660+
"/uploads/disentangling-preferences/cover.jpg": {
1661+
"sourceWidth": 4032,
1662+
"sourceHeight": 3024
1663+
},
1664+
"/uploads/disentangling-preferences/photo-20201228b.jpg": {
1665+
"sourceWidth": 4032,
1666+
"sourceHeight": 3024
1667+
},
1668+
"/uploads/disentangling-preferences/thuat-defense.jpg": {
1669+
"sourceWidth": 2618,
1670+
"sourceHeight": 1661
1671+
},
16561672
"/uploads/reproducibility-in-recommender-systems/cover.jpg": {
16571673
"sourceWidth": 2783,
16581674
"sourceHeight": 1878

‎src/data/generated-people.json‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
"title": "Associate Professor (SMU)",
88
"url": "http://www.hadylauw.com"
99
},
10+
{
11+
"slug": "jaime-hieu",
12+
"name": "Do Dinh Hieu, Jaime",
13+
"placement": "research-staff",
14+
"photo": "/team/members/jaime-hieu/photo.jpg",
15+
"title": "Research Scientist (SMU)",
16+
"role": "PhD (July 2025), Research Scientist (Nov 2026)",
17+
"alumniSort": "2026-11",
18+
"url": "https://jaimehd.com"
19+
},
1020
{
1121
"slug": "ezekiel",
1222
"name": "Ezekiel Ong Young",
@@ -71,16 +81,6 @@
7181
"title": "PhD co-supervisee (SMU)",
7282
"url": "https://hoangdv.me"
7383
},
74-
{
75-
"slug": "jaime-hieu",
76-
"name": "Do Dinh Hieu, Jaime",
77-
"placement": "alumni",
78-
"photo": "/team/members/jaime-hieu/photo.jpg",
79-
"title": "Research Scientist (SMU)",
80-
"role": "PhD (July 2025), Research Scientist (Nov 2026)",
81-
"alumniSort": "2026-11",
82-
"url": "https://jaimehd.com"
83-
},
8484
{
8585
"slug": "jiapeng",
8686
"name": "Lim Jia Peng",

‎src/data/generated-posts.json‎

Lines changed: 70 additions & 0 deletions
Large diffs are not rendered by default.

‎src/lib/markdown-posts.ts‎

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface MarkdownPost {
2525
author: string;
2626
excerpt: string;
2727
featuredImage: string;
28+
featured?: boolean;
2829
categories: string[];
2930
tags: string[];
3031
seoTitle: string;
@@ -39,10 +40,18 @@ export interface PostPreview {
3940
author: string;
4041
excerpt: string;
4142
featuredImage: string;
43+
featured?: boolean;
4244
categories: string[];
4345
tags: string[];
4446
}
4547

48+
function parsePostDate(value: unknown): string {
49+
if (value instanceof Date && !Number.isNaN(value.getTime())) {
50+
return value.toISOString().slice(0, 10);
51+
}
52+
return typeof value === "string" ? value.trim() : "";
53+
}
54+
4655
function parsePostFile(filename: string): MarkdownPost {
4756
const fullPath = path.join(postsDirectory, filename);
4857

@@ -61,10 +70,11 @@ function parsePostFile(filename: string): MarkdownPost {
6170
const post: MarkdownPost = {
6271
slug,
6372
title: data.title || "",
64-
date: data.date || "",
73+
date: parsePostDate(data.date),
6574
author: data.author || "",
6675
excerpt: data.excerpt || "",
6776
featuredImage: data.cover || data.featuredImage || "",
77+
featured: Boolean(data.featured),
6878
categories: data.categories || [],
6979
tags: data.tags || [],
7080
seoTitle: data.seoTitle || data.title || "",
@@ -107,12 +117,33 @@ export function loadAllPosts(): MarkdownPost[] {
107117
return posts;
108118
}
109119

120+
export function getFeaturedPost(): PostPreview | null {
121+
const allPosts = loadAllPosts();
122+
const pinned = allPosts.find((p) => p.featured);
123+
const target = pinned || allPosts[0];
124+
if (!target) return null;
125+
return {
126+
slug: target.slug,
127+
title: target.title,
128+
date: target.date,
129+
author: target.author,
130+
excerpt: target.excerpt,
131+
featuredImage: target.featuredImage,
132+
featured: Boolean(target.featured),
133+
categories: target.categories,
134+
tags: target.tags,
135+
};
136+
}
137+
110138
export function getAllPosts(
111139
page = 1,
112140
limit = 10,
113-
options?: { firstPageLimit?: number },
141+
options?: { firstPageLimit?: number; excludeSlug?: string },
114142
): { posts: PostPreview[]; total: number; pages: number } {
115-
const allPosts = loadAllPosts();
143+
let allPosts = loadAllPosts();
144+
if (options?.excludeSlug) {
145+
allPosts = allPosts.filter((post) => post.slug !== options.excludeSlug);
146+
}
116147

117148
const total = allPosts.length;
118149
const firstPageLimit = options?.firstPageLimit ?? limit;
@@ -140,6 +171,7 @@ export function getAllPosts(
140171
author: post.author,
141172
excerpt: post.excerpt,
142173
featuredImage: post.featuredImage,
174+
featured: Boolean(post.featured),
143175
categories: post.categories,
144176
tags: post.tags,
145177
}));
@@ -301,6 +333,10 @@ export function getAllPostSlugs(): string[] {
301333
}
302334

303335
export async function markdownToHtml(markdown: string): Promise<string> {
336+
const normalizedMarkdown = markdown.replace(
337+
/!\[([^\]]*)\]\s*!\[\]\(([^)]+)\)/g,
338+
"![$1]($2)",
339+
);
304340
const result = await unified()
305341
.use(remarkParse)
306342
.use(gfm)
@@ -316,6 +352,6 @@ export async function markdownToHtml(markdown: string): Promise<string> {
316352
strict: "error",
317353
})
318354
.use(rehypeStringify)
319-
.process(markdown);
355+
.process(normalizedMarkdown);
320356
return result.toString();
321357
}

0 commit comments

Comments
 (0)