diff --git a/astro.config.ts b/astro.config.ts index 9a85e439..b977d4b3 100644 --- a/astro.config.ts +++ b/astro.config.ts @@ -3,6 +3,7 @@ import expressiveCode from "astro-expressive-code"; import { defineConfig } from "astro/config"; import markdoc from "@astrojs/markdoc"; +import { rename } from "fs/promises"; // https://astro.build/config export default defineConfig({ @@ -24,5 +25,20 @@ export default defineConfig({ markdoc({ allowHTML: true, }), + { + name: "RSS Generator", + hooks: { + "astro:build:done": async (options) => { + const rssPages = options.pages.filter((page) => page.pathname.includes("rss")); + + for (const { pathname: rssPage } of rssPages) { + await rename( + new URL(`${rssPage}index.html`, options.dir), + new URL(`${rssPage}index.xml`, options.dir), + ); + } + }, + }, + }, ], }); diff --git a/src/pages/rss/blog.astro b/src/pages/rss/blog.astro new file mode 100644 index 00000000..49d673ae --- /dev/null +++ b/src/pages/rss/blog.astro @@ -0,0 +1,52 @@ +--- +export const partial = true; + +import { getCollection } from "astro:content"; +import { getBaseSiteURL, getURLFromEntry } from "$utils"; + +const articles = await getCollection("blog"); + +function makeIntro() { + return ` + + + My Blog + https://astro.build/blog + My blog about Astro + en + ${new Date().toUTCString()} + `.trim(); +} + +function makeOutro() { + return ` + + + `.trim(); +} +--- + + +{ + articles.map(async (article) => { + const start = `\t + ${article.data.title} + ${getBaseSiteURL().slice(0, -1)}${getURLFromEntry(article)} + ${article.data.tagline} + ${new Date(article.data.date).toUTCString()} + + \n`.trim(); + + const { Content } = await article.render(); + + return ( + <> + + + + + ); + }) +} +