31 lines
629 B
TypeScript
31 lines
629 B
TypeScript
import { readBlogPosts } from '~~/lib/blog/read-posts';
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const query = getQuery(event);
|
|
const include = (content) => {
|
|
const dateObj = new Date(content.date);
|
|
|
|
if (query.year) {
|
|
if (Number(query.year) !== dateObj.getFullYear()) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (query.month) {
|
|
if (Number(query.month) !== dateObj.getMonth() + 1) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (query.day) {
|
|
if (Number(query.day) !== dateObj.getDate()) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
};
|
|
|
|
return readBlogPosts(include);
|
|
});
|