import { NextResponse } from "next/server" import fs from "fs" import path from "path" interface ChangelogEntry { version: string date: string content: string url: 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 content by versions (assuming format ## [version] - date) const sections = fileContents.split(/^## /gm).filter((section) => section.trim()) for (const section of sections) { const lines = section.split("\n") const headerLine = lines[0] // Extract version and date from header const versionMatch = headerLine.match(/\[([^\]]+)\]/) const dateMatch = headerLine.match(/(\d{4}-\d{2}-\d{2})/) if (versionMatch) { const version = versionMatch[1] const date = dateMatch ? dateMatch[1] : new Date().toISOString().split("T")[0] const content = lines.slice(1).join("\n").trim() entries.push({ version, date, content, url: `${process.env.NEXT_PUBLIC_SITE_URL || "https://macrimi.github.io/ProxMenux"}/changelog#${version}`, }) } } return entries.slice(0, 10) // Latest 10 entries } catch (error) { console.error("Error parsing changelog:", error) return [] } } export async function GET() { const entries = await parseChangelog() const siteUrl = process.env.NEXT_PUBLIC_SITE_URL || "https://macrimi.github.io/ProxMenux" const rssXml = ` ProxMenux Changelog Latest updates and changes in ProxMenux ${siteUrl}/changelog en ${new Date().toUTCString()} ProxMenux RSS Generator ${entries .map( (entry) => ` ProxMenux ${entry.version} ${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", }, }) }