eleboog-astro/src/pages/newest/index.ts
Kebo c219a1d60a
Some checks are pending
ci / builder (push) Waiting to run
that should not happen either wow i am bad at this
2025-06-24 20:34:47 -05:00

21 lines
No EOL
494 B
TypeScript

import { compareDesc } from 'date-fns'
import { getCollection } from 'astro:content';
import type { APIRoute } from 'astro';
const posts = await getCollection('posts')
const newestPost = posts.sort(
(a, b) => compareDesc(new Date(a.data.date), new Date(b.data.date))
).filter((e) => {
if (e.data.draft) {
return false;
} else return true;
})[0];
console.log(newestPost.slug)
export const GET: APIRoute = ({ redirect }) => {
return redirect('/posts/' + newestPost.slug, 307);
}