merge in new changes
Some checks failed
renovate / renovate (push) Has been cancelled
test-build / build (push) Has been cancelled

This commit is contained in:
2025-08-11 16:24:43 -05:00
parent a484feb7cd
commit 1dc4ccfbc6
125 changed files with 9304 additions and 20383 deletions

View File

@@ -1,10 +1,26 @@
import rss from '@astrojs/rss';
// copy from https://github.com/delucis/astro-blog-full-text-rss
// see https://github.com/delucis/astro-blog-full-text-rss/blob/latest/src/pages/rss.xml.ts
// get more context
import directus from '../lib/directus';
import { getContainerRenderer as getMDXRenderer } from '@astrojs/mdx';
import rss, { type RSSFeedItem } from '@astrojs/rss';
import type { APIContext } from 'astro';
import { transform, walk } from 'ultrahtml';
import sanitize from 'ultrahtml/transformers/sanitize';
import { readItems, readSingleton } from '@directus/sdk';
export async function GET(context: any) {
const global = await directus.request(readSingleton('global'));
import directus from '@lib/directus';
const global = await directus.request(readSingleton('site_global'));
export async function GET(context: APIContext) {
// Get the URL to prepend to relative site links. Based on `site` in `astro.config.mjs`.
let baseUrl = context.site?.href || global.site_url;
if (baseUrl.at(-1) === '/') {
baseUrl = baseUrl.slice(0, -1);
}
// Load the content collection entries to add to our RSS feed.
const posts = await directus.request(
readItems('posts', {
fields: ['*'],
@@ -12,16 +28,30 @@ export async function GET(context: any) {
})
);
const feedItems: RSSFeedItem[] = [];
for (const post of posts) {
const content = await transform(post.content.replace(/^<!DOCTYPE html>/, ''), [
async (node) => {
await walk(node, (node) => {
if (node.name === 'a' && node.attributes.href?.startsWith('/')) {
node.attributes.href = baseUrl + node.attributes.href;
}
if (node.name === 'img' && node.attributes.src?.startsWith('/')) {
node.attributes.src = baseUrl + node.attributes.src;
}
});
return node;
},
sanitize({ dropElements: ['script', 'style'] }),
]);
feedItems.push({ ...post, link: `/blog/${post.slug}/`, content });
}
// Return our RSS feed XML response.
return rss({
title: `${global.name}`,
description: `${global.description}`,
site: context.site,
items: posts.map((post) => ({
title: post.title,
pubDate: post.published_date,
description: post.slug,
link: `/blog/${post.slug}/`,
categories: post.tags || [],
})),
title: global.name,
description: global.about,
site: baseUrl,
items: feedItems,
});
}