lunasqu.ee-nuxt/server/api/blog/archive.ts

22 lines
539 B
TypeScript
Raw Normal View History

2022-10-16 09:37:13 +00:00
import { getArchiveTree } from '~~/lib/blog/read-posts';
2024-04-20 17:32:12 +00:00
import type { BlogPost } from '~~/lib/types/post';
2022-10-16 09:37:13 +00:00
export default defineEventHandler(async (event) => {
2022-10-16 11:04:03 +00:00
const query = getQuery(event);
2022-12-02 16:52:51 +00:00
const include = (content: BlogPost) => {
2022-10-16 11:04:03 +00:00
if (query.tag) {
2022-12-02 16:52:51 +00:00
const tags = Array.isArray(query.tag) ? query.tag : [query.tag];
if (
!content.tags?.length ||
!tags.every((tag) => content.tags.includes(tag))
) {
2022-10-16 11:04:03 +00:00
return false;
}
}
return true;
};
return getArchiveTree(include);
2022-10-16 09:37:13 +00:00
});