[4] fresh score=286
Captured at: 2026-11-04T06:18:52Z (1 minute ago)
Instruction: Explain how selected posts and drafts reach the homepage. Preserve the file paths and the exact filtering expressions. Keep the answer short.
Command: cat src/lib/post-schema.mjs src/lib/posts.ts src/pages/index.astro
Exit code: 0
Files: src/lib/posts.ts
Matched: fts, instruction, compressed_output, command, file_paths, vector
Summary:
import { z } from 'astro/zod';
export const postSchema = z.object({
title: z.string().trim().min(1),
description: z.string().trim().min(1),
date: z.iso.date(),
draft: z.boolean().default(false),
selected: z.boolean().default(false),
tags: z.array(z.string().trim().min(1)).default([]),
cover: z.string().regex(/^\/images\/(?:[a-z0-9-]+\/)*[a-z0-9-]+\.(?:webp|avif|png|jpe?g)$/,
'Use a local image URL such as /images/blog/my-post.webp').optional(),
coverAlt: z.string().trim().min(1).optional(),
legacyUrls: z.array(z.string().regex(/^\/(?:blog\/)?\d{4}\/\d{2}\/\d{2}\/[a-z0-9-]+\.html$/)).default([]),
}).refine(post => Boolean(post.cover) === Boolean(post.coverAlt), {
message: 'Provide both cover and coverAlt, or omit both for a text-only post.',
path: ['coverAlt'],
});
import { getCollection } from 'astro:content';
export async function publishedPosts() {
const posts = await getCollection('blog', ({ data }) => !data.draft);
const aliases = new Set<string>();
for (const post of posts) {
for (const url of post.data.legacyUrls) {
if (aliases.has(url)) throw new Error(`Duplicate legacy URL: ${url}`);
aliases.add(url);
}
}
return posts.sort((a, b) => b.data.date.localeCompare(a.data.date) || a.id.localeCompare(b.id));
}
