lunasqu.ee-nuxt/server/api/blog/archive.ts
2024-04-20 20:32:12 +03:00

22 lines
539 B
TypeScript

import { getArchiveTree } from '~~/lib/blog/read-posts';
import type { BlogPost } from '~~/lib/types/post';
export default defineEventHandler(async (event) => {
const query = getQuery(event);
const include = (content: BlogPost) => {
if (query.tag) {
const tags = Array.isArray(query.tag) ? query.tag : [query.tag];
if (
!content.tags?.length ||
!tags.every((tag) => content.tags.includes(tag))
) {
return false;
}
}
return true;
};
return getArchiveTree(include);
});