From 40d4d18e87a10e717b2b53f2cb00de25e76ee303 Mon Sep 17 00:00:00 2001
From: Princesseuh <3019731+Princesseuh@users.noreply.github.com>
Date: Sat, 16 Mar 2024 13:09:19 +0100
Subject: [PATCH] feat: trying a funky way of doing RSS
---
astro.config.ts | 16 +++++++++++++
src/pages/rss/blog.astro | 52 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 68 insertions(+)
create mode 100644 src/pages/rss/blog.astro
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 (
+ <>
+
+
+
+ >
+ );
+ })
+}
+