nicholai-work-2026/src/pages/search.json.ts
Nicholai adf3f376ba Add search with lunr and read time to site
- Add lunr dependency to package.json and pnpm-lock.yaml.
- Implement SearchDialog component for full‑text search using lunr.
- Add readTime prop to BlogCard with default 5 min read.
- Add reading‑time utility for estimated read duration.
- Update layout and page components to include new props.
- Generate search.json data for indexing.

Hubert The Eunuch
2025-12-24 03:48:51 -07:00

24 lines
544 B
TypeScript

import { getCollection } from 'astro:content';
export async function GET() {
const posts = await getCollection('blog');
const searchData = posts.map((post) => ({
id: post.id,
title: post.data.title,
description: post.data.description,
content: post.body,
category: post.data.category || '',
tags: post.data.tags || [],
url: `/blog/${post.id}/`,
pubDate: post.data.pubDate.toISOString(),
}));
return new Response(JSON.stringify(searchData), {
status: 200,
headers: {
'Content-Type': 'application/json',
},
});
}