feat: add XSL stylesheet for feeds and fix sorting order

This commit is contained in:
Stefan Imhoff
2023-06-21 12:45:59 +02:00
parent c7b3693029
commit db20b50c98
6 changed files with 120 additions and 3 deletions

75
public/rss.xsl Normal file

File diff suppressed because one or more lines are too long

View File

@@ -2,10 +2,11 @@
import { site } from '../data/site'; import { site } from '../data/site';
import { dateToISO } from '../utils'; import { dateToISO } from '../utils';
import { mapping } from '../mdx-components'; import { rssMapping } from '../mdx-components';
const { allPosts } = Astro.props; const { allPosts } = Astro.props;
const rssHeaderXml = `<?xml version="1.0" encoding="UTF-8"?> const rssHeaderXml = `<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/rss.xsl" type="text/xsl"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel> <channel>
<title>${site.title}</title> <title>${site.title}</title>
@@ -22,14 +23,14 @@ const rssFooterXml = ` </channel>
<> <>
<Fragment <Fragment
set:html={` <item> set:html={` <item>
<title>${post.frontmatter.title}</title> <title>${post.frontmatter.title.replace('&', '&amp;')}</title>
<link>${`${site.url}/${post.frontmatter.slug}/`}</link> <link>${`${site.url}/${post.frontmatter.slug}/`}</link>
<guid>${`${site.url}/${post.frontmatter.slug}/`}</guid> <guid>${`${site.url}/${post.frontmatter.slug}/`}</guid>
<description><![CDATA[${post.frontmatter.description}]]></description> <description><![CDATA[${post.frontmatter.description}]]></description>
<pubDate>${dateToISO(post.frontmatter.date)}</pubDate> <pubDate>${dateToISO(post.frontmatter.date)}</pubDate>
<content:encoded><![CDATA[`} <content:encoded><![CDATA[`}
/> />
<post.Content components={mapping} /> <post.Content components={rssMapping} />
<Fragment <Fragment
set:html={`]]></content:encoded> set:html={`]]></content:encoded>
</item> </item>

View File

@@ -79,3 +79,32 @@ export const mapping = {
Verse, Verse,
YouTube, 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,
};

View File

@@ -2,10 +2,14 @@ import rss from '@astrojs/rss';
import { getCollection } from 'astro:content'; import { getCollection } from 'astro:content';
import { site } from '../data/site'; import { site } from '../data/site';
import { sortBySortKey } from '../utils';
export async function get(context) { export async function get(context) {
const aiArt = await getCollection('ai-art'); const aiArt = await getCollection('ai-art');
aiArt.sort(sortBySortKey);
return rss({ return rss({
stylesheet: '/rss.xsl',
title: `${site.title} (AI Art)`, title: `${site.title} (AI Art)`,
description: 'This is a collection of AI art pieces Ive created with Stable Diffusion.', description: 'This is a collection of AI art pieces Ive created with Stable Diffusion.',
site: context.site, site: context.site,

View File

@@ -2,10 +2,14 @@ import rss from '@astrojs/rss';
import { getCollection } from 'astro:content'; import { getCollection } from 'astro:content';
import { site } from '../data/site'; import { site } from '../data/site';
import { sortByDate } from '../utils';
export async function get(context) { export async function get(context) {
const haiku = await getCollection('haiku'); const haiku = await getCollection('haiku');
haiku.sort(sortByDate);
return rss({ return rss({
stylesheet: '/rss.xsl',
title: `${site.title} (Haiku)`, title: `${site.title} (Haiku)`,
description: 'This is an ever-growing collection of Haiku I have written.', description: 'This is an ever-growing collection of Haiku I have written.',
site: context.site, site: context.site,

View File

@@ -2,10 +2,14 @@ import rss from '@astrojs/rss';
import { getCollection } from 'astro:content'; import { getCollection } from 'astro:content';
import { site } from '../data/site'; import { site } from '../data/site';
import { sortBySortKey } from '../utils';
export async function get(context) { export async function get(context) {
const sketchnotes = await getCollection('sketchnotes'); const sketchnotes = await getCollection('sketchnotes');
sketchnotes.sort(sortBySortKey).reverse();
return rss({ return rss({
stylesheet: '/rss.xsl',
title: `${site.title} (Sketchnotes)`, title: `${site.title} (Sketchnotes)`,
description: 'This is a collection of Sketchnotes Ive drawn.', description: 'This is a collection of Sketchnotes Ive drawn.',
site: context.site, site: context.site,