2022-10-16 09:37:13 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-16 11:04:03 +00:00
|
|
|
if (query.tag) {
|
|
|
|
if (!content.tags?.length || !content.tags.includes(query.tag)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-16 09:37:13 +00:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2022-10-16 11:04:03 +00:00
|
|
|
return readBlogPosts(
|
|
|
|
include,
|
|
|
|
query.render !== 'false',
|
|
|
|
query.body !== 'false'
|
|
|
|
);
|
2022-10-16 09:37:13 +00:00
|
|
|
});
|