import { error, redirect } from '@sveltejs/kit';
import type { RequestHandler } from './$types';
import { ARTICLE_SLUGS, articleTarget, type ArticleSlug } from '$lib/articles';

export const GET: RequestHandler = ({ params }) => {
	const { slug } = params;
	if (!(ARTICLE_SLUGS as readonly ArticleSlug[]).filter((x) => x.slug === slug)) {
		error(404, 'Unknown article');
	}
	const target = articleTarget(slug);
	if (!target) {
		error(500, 'Article target not found');
	}
	redirect(301, target);
};
