import { NextResponse } from "next/server" import fs from "fs" import path from "path" interface ChangelogEntry { version: string date: string content: string url: string title: string } async function parseChangelog(): Promise { try { const changelogPath = path.join(process.cwd(), "..", "CHANGELOG.md") if (!fs.existsSync(changelogPath)) { return [] } const fileContents = fs.readFileSync(changelogPath, "utf8") const entries: ChangelogEntry[] = [] // Split by any heading (## or ###) to catch all changes, not just versions const sections = fileContents.split(/^(##\s+.*$)/gm).filter((section) => section.trim()) for (let i = 0; i < sections.length - 1; i += 2) { const headerLine = sections[i] const content = sections[i + 1] || "" // Check if it's a version header (## [version] - date) const versionMatch = headerLine.match(/##\s+\[([^\]]+)\]\s*-\s*(\d{4}-\d{2}-\d{2})/) if (versionMatch) { const version = versionMatch[1] const date = versionMatch[2] entries.push({ version, date, content: content.trim(), url: `https://macrimi.github.io/ProxMenux/changelog#${version}`, title: `ProxMenux ${version}`, }) } else { // Check for date-only headers (## 2025-05-13) const dateMatch = headerLine.match(/##\s+(\d{4}-\d{2}-\d{2})/) if (dateMatch) { const date = dateMatch[1] entries.push({ version: date, date, content: content.trim(), url: `https://macrimi.github.io/ProxMenux/changelog#${date}`, title: `ProxMenux Update ${date}`, }) } } } return entries.slice(0, 15) // Latest 15 entries } catch (error) { console.error("Error parsing changelog:", error) return [] } } export async function GET() { const entries = await parseChangelog() const siteUrl = "https://macrimi.github.io/ProxMenux" const rssXml = ` ProxMenux Changelog Latest updates and changes in ProxMenux ${siteUrl}/changelog en-US ${new Date().toUTCString()} ProxMenux RSS Generator 60 ${entries .map( (entry) => ` ${entry.title} 500 ? "..." : ""}]]> ${entry.url} ${entry.url} ${new Date(entry.date).toUTCString()} Changelog `, ) .join("")} ` return new NextResponse(rssXml, { headers: { "Content-Type": "application/rss+xml; charset=utf-8", "Cache-Control": "public, max-age=3600, s-maxage=3600", }, }) }