import { readFileSync, writeFileSync } from "fs";
import { join } from "path";
interface Post {
slug: string;
title: string;
excerpt: string;
date: string;
author: string;
tags: string[];
body: string;
}
function escapeXml(str: string): string {
return str
.replace(/&/g, "&")
.replace(//g, ">")
.replace(/"/g, """)
.replace(/'/g, "'");
}
const postsPath = join(__dirname, "../src/data/posts.json");
const posts = (JSON.parse(readFileSync(postsPath, "utf-8")) as Post[]).sort(
(a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()
);
const items = posts
.map(
(post) => ` -
${escapeXml(post.title)}
https://thesvg.org/blog/${post.slug}
https://thesvg.org/blog/${post.slug}
${escapeXml(post.excerpt)}
${new Date(post.date).toUTCString()}
team@thesvg.org (${post.author})
${post.tags.map((t) => `${escapeXml(t)}`).join("\n ")}
`
)
.join("\n");
const rss = `
theSVG Blog
https://thesvg.org/blog
Announcements, releases, and updates from theSVG - the open SVG brand library
en-us
${new Date().toUTCString()}
${items}
`;
const outPath = join(__dirname, "../public/feed.xml");
writeFileSync(outPath, rss, "utf-8");
console.log(`Generated feed.xml with ${posts.length} posts`);