lunasqu.ee-nuxt/server/api/blog/archive.ts
2022-12-02 18:52:51 +02:00

22 lines
534 B
TypeScript

import { getArchiveTree } from '~~/lib/blog/read-posts';
import { 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);
});