Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | 1x 5x 5x 5x 53x 5x 42x 43x 5x 5x 1x | import { Feed } from "feed";
import { JOURNAL } from "../../shared/constants";
import { toPermalink } from "../mappers/page";
import { getArticleIndex } from "../services/articleIndex";
const FEED_LENGTH = 20;
export default defineEventHandler(async (event): Promise<string> => {
const {
public: { site },
} = useRuntimeConfig(event);
const feed = new Feed({
title: JOURNAL.name,
link: toPermalink("", site.url),
language: "es",
feedLinks: { rss: new URL("/feed/", site.url).href },
generator: false,
});
const articles = (await getArticleIndex(event))
.filter(({ noindex, publishedAt }) => !noindex && publishedAt)
.slice(0, FEED_LENGTH);
for (const { slug, title, excerpt, publishedAt, authors, category } of articles) {
feed.addItem({
title,
link: toPermalink(slug, site.url),
date: new Date(publishedAt!),
description: excerpt,
author: authors.map(({ name }) => ({ name })),
category: category ? [{ name: category.name }] : undefined,
});
}
setResponseHeader(event, "content-type", "application/rss+xml; charset=utf-8");
return feed.rss2();
});
defineRouteMeta({
openAPI: {
tags: ["SEO"],
summary: "The newest articles as an RSS 2.0 feed",
},
});
|