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)))[0];

console.log(newestPost.slug)

export const GET: APIRoute = ({ redirect }) => {
  return redirect('https://eleboog.com/posts/' + newestPost.slug, 307);
}