diff options
Diffstat (limited to 'src/pages')
| -rw-r--r-- | src/pages/blog/[...slug].astro | 15 | ||||
| -rw-r--r-- | src/pages/feed.xml.js | 41 |
2 files changed, 40 insertions, 16 deletions
diff --git a/src/pages/blog/[...slug].astro b/src/pages/blog/[...slug].astro index 5ba6b3b..907f64e 100644 --- a/src/pages/blog/[...slug].astro +++ b/src/pages/blog/[...slug].astro @@ -1,9 +1,9 @@ --- import { type CollectionEntry, getCollection, render } from "astro:content"; +import dayjs from "dayjs"; import blogPostSchema from "../../utils/schemas/blogPostSchema"; import breadcrumbSchema from "../../utils/schemas/breadcrumbSchema"; import Comments from "../../components/Comments.astro"; -import dayjs from "dayjs"; import Layout from "../../layouts/BaseLayout.astro"; import personSchema from "../../utils/schemas/personSchema"; import websiteSchema from "../../utils/schemas/websiteSchema"; @@ -31,9 +31,10 @@ const isBasedOn = post.data.basedOn; const lang = post.data.lang; const preview = `/images/preview/${post.id}.png`; const slug = post.id; -const title = post.data.title; +const headline = post.data.title; +const title = `${post.data.title} | Valentin Popov`; -const dateModified = post.data.dateModified?.toISOString(); +const dateModified = (post.data.dateModified ?? post.data.datePublished).toISOString(); const datePublished = post.data.datePublished.toISOString(); const formattedDate = dayjs(post.data.datePublished.toString()).format("MMMM DD, YYYY"); @@ -51,14 +52,14 @@ const schema = [ lang, preview, slug, - title, + title: headline, }), breadcrumbSchema({ siteUrl, items: [ { name: "Home", url: "/" }, { name: "Blog", url: "/blog/" }, - { name: title, url: `/blog/${slug}` }, + { name: headline, url: `/blog/${slug}` }, ], }), ]; @@ -72,10 +73,10 @@ const schema = [ } </style> -<Layout title={title} description={description} preview={preview} lang={lang} schema={schema}> +<Layout title={title} description={description} preview={preview} lang={lang} schema={schema} ogType="article" publishedTime={datePublished} modifiedTime={dateModified}> <article> <header> - <h1>{title}</h1> + <h1>{headline}</h1> <p> <small> 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, }); } |
