aboutsummaryrefslogtreecommitdiff
path: root/src/pages/feed.xml.js
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-04-22 20:53:21 +0300
committerValentin Popov <valentin@popov.link>2026-04-22 20:53:21 +0300
commit933d6874b1fe1dbb113e9de39425f2d713a72408 (patch)
tree44278a4088a2144ac08fb72fd4abe86ab60a55e8 /src/pages/feed.xml.js
parent5e818d804d5d38beff0f3754a006333752fd5082 (diff)
downloadpopov.link-933d6874b1fe1dbb113e9de39425f2d713a72408.tar.xz
popov.link-933d6874b1fe1dbb113e9de39425f2d713a72408.zip
feat: enhance blog and SEO features with new plugins and metadata
- Introduced rehypeLazyImages plugin for lazy loading images in blog posts. - Updated sitemap integration to include last modified dates for blog posts. - Enhanced Head and BaseLayout components to support additional Open Graph metadata. - Improved RSS feed generation with sanitized content and author information. - Updated manifest.json for a darker theme and standalone display mode. - Added support for language-specific attributes in various components. - Refactored blog post handling to include modified and published timestamps.
Diffstat (limited to 'src/pages/feed.xml.js')
-rw-r--r--src/pages/feed.xml.js41
1 files changed, 32 insertions, 9 deletions
diff --git a/src/pages/feed.xml.js b/src/pages/feed.xml.js
index 5aea78b..005f2d8 100644
--- a/src/pages/feed.xml.js
+++ b/src/pages/feed.xml.js
@@ -1,24 +1,47 @@
import { getCollection } from "astro:content";
+import MarkdownIt from "markdown-it";
import rss from "@astrojs/rss";
+import sanitizeHtml from "sanitize-html";
+import { config } from "../config";
+
+const parser = new MarkdownIt({ html: true, linkify: true });
export async function GET(context) {
const title = "RSS Feed | Valentin Popov Blog";
const description = "Follow the latest posts from Valentin Popov via RSS.";
- const posts = await getCollection("blog", ({ data }) => {
- return data.draft !== true;
- });
+ const posts = (await getCollection("blog", ({ data }) => data.draft !== true)).sort((a, b) => b.data.datePublished.getTime() - a.data.datePublished.getTime());
+
+ const feedUrl = new URL("/feed.xml", context.site).toString();
return rss({
- customData: `<language>en</language>`,
- description: description,
+ title,
+ description,
+ site: context.site,
+ xmlns: {
+ atom: "http://www.w3.org/2005/Atom",
+ content: "http://purl.org/rss/1.0/modules/content/",
+ dc: "http://purl.org/dc/elements/1.1/",
+ },
+ customData: [`<language>en</language>`, `<atom:link href="${feedUrl}" rel="self" type="application/rss+xml"/>`].join(""),
items: posts.map((post) => ({
+ title: post.data.title,
description: post.data.description,
- link: `/blog/${post.id}`,
+ link: `/blog/${post.id}/`,
pubDate: post.data.datePublished,
- title: post.data.title,
+ author: `${config.author.email} (${config.author.name})`,
+ content: sanitizeHtml(parser.render(post.body ?? ""), {
+ allowedTags: sanitizeHtml.defaults.allowedTags.concat(["img", "pre", "code", "span"]),
+ allowedAttributes: {
+ ...sanitizeHtml.defaults.allowedAttributes,
+ img: ["src", "alt", "title", "loading", "decoding"],
+ code: ["class"],
+ span: ["class", "style"],
+ pre: ["class", "style"],
+ a: ["href", "name", "target", "rel"],
+ },
+ }),
+ customData: `<dc:language>${post.data.lang}</dc:language>`,
})),
- site: context.site,
- title: title,
});
}