chore: myriad fixes + book year pages
This commit is contained in:
parent
3ab6f77a69
commit
aec8471b06
45 changed files with 508 additions and 293 deletions
62
src/pages/feeds/syndication.xml.js
Normal file
62
src/pages/feeds/syndication.xml.js
Normal file
|
@ -0,0 +1,62 @@
|
|||
import { DateTime } from "luxon";
|
||||
import fetchSyndication from '@utils/data/syndication.js';
|
||||
import { fetchGlobals } from '@utils/data/globals.js';
|
||||
import { dateToRFC822, encodeAmp, md } from '@utils/helpers/general.js';
|
||||
|
||||
const generateSyndicationRSS = async () => {
|
||||
const globals = await fetchGlobals();
|
||||
const entries = await fetchSyndication();
|
||||
|
||||
if (!entries.length) throw new Error('No feed entries found.');
|
||||
|
||||
const title = globals.site_name || 'Syndicated Content Feed';
|
||||
const permalink = '/feeds/syndication.xml';
|
||||
|
||||
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
||||
<channel>
|
||||
<atom:link href="${globals.url}${permalink}" rel="self" type="application/rss+xml" />
|
||||
<title><![CDATA[${title}]]></title>
|
||||
<description><![CDATA[${globals.site_description || ''}]]></description>
|
||||
<link>${globals.url}</link>
|
||||
<lastBuildDate>${dateToRFC822(DateTime.now())}</lastBuildDate>
|
||||
<image>
|
||||
<title><![CDATA[${title}]]></title>
|
||||
<link>${globals.url}</link>
|
||||
<url>${globals.cdn_url}${globals.avatar}?class=w200</url>
|
||||
<width>144</width>
|
||||
<height>144</height>
|
||||
</image>
|
||||
${entries
|
||||
.slice(0, 20)
|
||||
.map(
|
||||
(entry) => `
|
||||
<item>
|
||||
<title><![CDATA[${entry.syndication.title || 'Untitled'}]]></title>
|
||||
<link>${encodeAmp(entry.syndication.url)}</link>
|
||||
<pubDate>${dateToRFC822(entry.syndication.date)}</pubDate>
|
||||
<guid isPermaLink="false">${encodeAmp(entry.syndication.url)}</guid>
|
||||
<description><![CDATA[${md(entry.syndication.description || '')}]]></description>
|
||||
</item>`
|
||||
)
|
||||
.join('')}
|
||||
</channel>
|
||||
</rss>`;
|
||||
|
||||
return xml;
|
||||
};
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const rss = await generateSyndicationRSS();
|
||||
return new Response(rss, {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/rss+xml' },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error.message);
|
||||
return new Response('Error generating syndication feed.', { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
export const prerender = true;
|
Reference in a new issue