2022-10-16 12:50:21 +00:00
|
|
|
import { Feed } from 'feed';
|
2022-10-16 16:17:55 +00:00
|
|
|
import { getFilteredBlogPosts } from '~~/lib/blog/read-posts';
|
2022-10-16 12:50:21 +00:00
|
|
|
|
|
|
|
const BASE_URL = 'https://lunasqu.ee/blog';
|
|
|
|
|
|
|
|
export default defineEventHandler(async (event) => {
|
2022-10-16 16:17:55 +00:00
|
|
|
const posts = await getFilteredBlogPosts(undefined, true, false);
|
2022-10-16 12:50:21 +00:00
|
|
|
const feed = new Feed({
|
|
|
|
title: "Evert's Blog",
|
|
|
|
description: 'Projects and Tutorials',
|
|
|
|
id: BASE_URL,
|
|
|
|
link: BASE_URL,
|
|
|
|
copyright: 'Evert "Diamond" Prants 2022',
|
|
|
|
language: 'en',
|
|
|
|
updated: new Date(posts[0].date),
|
|
|
|
generator: 'https://gitlab.icynet.eu/evert/lunasqu.ee-nuxt',
|
|
|
|
feedLinks: {
|
|
|
|
atom: `${BASE_URL}/atom.xml`,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
posts.forEach((post) => {
|
|
|
|
const description = post.html
|
|
|
|
.replace(/<[^>]*>?/gm, '')
|
|
|
|
.replace('\n', ' ')
|
|
|
|
.substring(0, 240);
|
|
|
|
|
|
|
|
feed.addItem({
|
|
|
|
title: post.title,
|
|
|
|
id: `${BASE_URL}/${post.fullSlug}`,
|
|
|
|
link: `${BASE_URL}/${post.fullSlug}`,
|
|
|
|
description,
|
|
|
|
content: post.html,
|
|
|
|
date: new Date(post.date),
|
|
|
|
published: new Date(post.date),
|
|
|
|
category: post.tags.map((tag) => ({
|
|
|
|
term: tag,
|
|
|
|
scheme: `${BASE_URL}/tags/${tag}`,
|
|
|
|
})),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
appendResponseHeader(event, 'Content-Type', 'text/xml');
|
|
|
|
|
|
|
|
return feed.atom1();
|
|
|
|
});
|