From db20b50c985c79b8d7aaf51a22b012f8901fd4b7 Mon Sep 17 00:00:00 2001 From: Stefan Imhoff Date: Wed, 21 Jun 2023 12:45:59 +0200 Subject: [PATCH] feat: add XSL stylesheet for feeds and fix sorting order --- public/rss.xsl | 75 ++++++++++++++++++++++++++++++++ src/components/RssXml.astro | 7 +-- src/mdx-components.ts | 29 ++++++++++++ src/pages/rss-ai-art.xml.js | 4 ++ src/pages/rss-haiku.xml.js | 4 ++ src/pages/rss-sketchnotes.xml.js | 4 ++ 6 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 public/rss.xsl diff --git a/public/rss.xsl b/public/rss.xsl new file mode 100644 index 0000000..f408bf8 --- /dev/null +++ b/public/rss.xsl @@ -0,0 +1,75 @@ + + + + + + + <xsl:value-of select="/rss/channel/title"/> Web Feed + + + + + + +
+
+

+ + + + + + + + + + + + + + + + + + + Web Feed Preview +

+

+

+ + + + + Visit Website → + +
+

Recent Items

+ +
+

+ + + + + + +

+ + Published: + +
+
+
+ + +
+
diff --git a/src/components/RssXml.astro b/src/components/RssXml.astro index 8dea823..f5aad8e 100644 --- a/src/components/RssXml.astro +++ b/src/components/RssXml.astro @@ -2,10 +2,11 @@ import { site } from '../data/site'; import { dateToISO } from '../utils'; -import { mapping } from '../mdx-components'; +import { rssMapping } from '../mdx-components'; const { allPosts } = Astro.props; const rssHeaderXml = ` + ${site.title} @@ -22,14 +23,14 @@ const rssFooterXml = ` <> - ${post.frontmatter.title} + ${post.frontmatter.title.replace('&', '&')} ${`${site.url}/${post.frontmatter.slug}/`} ${`${site.url}/${post.frontmatter.slug}/`} ${dateToISO(post.frontmatter.date)} - + diff --git a/src/mdx-components.ts b/src/mdx-components.ts index 768d963..0eaa4c8 100644 --- a/src/mdx-components.ts +++ b/src/mdx-components.ts @@ -79,3 +79,32 @@ export const mapping = { Verse, YouTube, }; + +// Mapping for RSS feed to reduce the size of the feed +export const rssMapping = { + AffiliateLink, + AmazonBook, + Banner, + Blockquote, + Book, + Bookshelf, + ColorStack, + ColorSwatch, + DisplayBox, + DownloadLink, + EmailLink, + Figure, + Flag, + Image, + MarkdownImage, + MoreLink, + NetflixFlag, + OdyseeVideo, + Picture, + PrimeVideoFlag, + ProjectIntro, + Pullquote, + ThemeBox, + Verse, + YouTube, +}; diff --git a/src/pages/rss-ai-art.xml.js b/src/pages/rss-ai-art.xml.js index 1860480..f1d88c9 100644 --- a/src/pages/rss-ai-art.xml.js +++ b/src/pages/rss-ai-art.xml.js @@ -2,10 +2,14 @@ import rss from '@astrojs/rss'; import { getCollection } from 'astro:content'; import { site } from '../data/site'; +import { sortBySortKey } from '../utils'; export async function get(context) { const aiArt = await getCollection('ai-art'); + aiArt.sort(sortBySortKey); + return rss({ + stylesheet: '/rss.xsl', title: `${site.title} (AI Art)`, description: 'This is a collection of AI art pieces I’ve created with Stable Diffusion.', site: context.site, diff --git a/src/pages/rss-haiku.xml.js b/src/pages/rss-haiku.xml.js index 25c9fec..a85a650 100644 --- a/src/pages/rss-haiku.xml.js +++ b/src/pages/rss-haiku.xml.js @@ -2,10 +2,14 @@ import rss from '@astrojs/rss'; import { getCollection } from 'astro:content'; import { site } from '../data/site'; +import { sortByDate } from '../utils'; export async function get(context) { const haiku = await getCollection('haiku'); + haiku.sort(sortByDate); + return rss({ + stylesheet: '/rss.xsl', title: `${site.title} (Haiku)`, description: 'This is an ever-growing collection of Haiku I have written.', site: context.site, diff --git a/src/pages/rss-sketchnotes.xml.js b/src/pages/rss-sketchnotes.xml.js index 9029be0..726ee33 100644 --- a/src/pages/rss-sketchnotes.xml.js +++ b/src/pages/rss-sketchnotes.xml.js @@ -2,10 +2,14 @@ import rss from '@astrojs/rss'; import { getCollection } from 'astro:content'; import { site } from '../data/site'; +import { sortBySortKey } from '../utils'; export async function get(context) { const sketchnotes = await getCollection('sketchnotes'); + sketchnotes.sort(sortBySortKey).reverse(); + return rss({ + stylesheet: '/rss.xsl', title: `${site.title} (Sketchnotes)`, description: 'This is a collection of Sketchnotes I’ve drawn.', site: context.site,