Skip to content

Commit

Permalink
Clean up HTML formatting in XML descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
fwextensions committed Oct 12, 2024
1 parent 4a96aaa commit 75ff5b3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/pages/rss.xml.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import rss from "@astrojs/rss";
import { getCollection } from "astro:content";
import { dateFromSlug, formatRSSDate } from "@/utils";
import { dateFromSlug } from "@/utils";

const DescriptionPattern = /\s*<p>(.*)<\/p>/;

export async function GET(context)
{
Expand All @@ -16,11 +18,15 @@ export async function GET(context)
date = dateFromSlug(slug),
},
} = post;
// we want to include any embedded HTML, like anchors, but don't want the
// description surrounded by <p> tags
const description = descriptionHTML.match(DescriptionPattern)?.[1] || descriptionHTML;


return {
title,
description: descriptionHTML,
pubDate: formatRSSDate(date),
description,
pubDate: date,
link: `/blog/${slug}`,
};
});
Expand Down

0 comments on commit 75ff5b3

Please sign in to comment.