-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RSS feed functionality and update dependencies
- Loading branch information
Showing
4 changed files
with
90 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import rss from '@astrojs/rss'; | ||
import { getCollection } from 'astro:content'; | ||
import type { CollectionEntry } from 'astro:content'; | ||
import { experimental_AstroContainer as AstroContainer } from "astro/container"; | ||
import { getContainerRenderer as getMDXRenderer } from "@astrojs/mdx"; | ||
import { loadRenderers } from "astro:container"; | ||
|
||
|
||
type Note = CollectionEntry<"notes">; | ||
|
||
|
||
export async function GET(context) { | ||
|
||
const renderers = await loadRenderers([getMDXRenderer()]); | ||
const container = await AstroContainer.create({ renderers }); | ||
|
||
const noteEntries = await getCollection("notes", ({ data }: Note) => { | ||
return import.meta.env.PROD ? data.isDraft !== true : true; | ||
}); | ||
|
||
const items = []; | ||
for (const note of noteEntries) { | ||
|
||
const { Content } = await note.render(); | ||
const content = await container.renderToString(Content); | ||
items.push({ | ||
title: note.data.title, | ||
pubDate: note.data.createdAt, | ||
link: `/notes/${note.slug}`, | ||
content: content | ||
}); | ||
} | ||
|
||
return rss({ | ||
title: "matttrent.com notes feed", | ||
description: "matttrent.com notes feed", | ||
site: context.site, | ||
trailingSlash: false, | ||
items: items | ||
}); | ||
} |