This commit is contained in:
Raven Scott 2024-10-17 04:47:46 -04:00
parent 0fc95f7e5e
commit e1f61e55dc

26
app.js
View File

@ -105,6 +105,32 @@ app.get('/track/:slug', async (req, res) => {
res.render('track', { track }); res.render('track', { track });
}); });
// JSON endpoint to return cached tracks
app.get('/json', async (req, res) => {
const allTracks = await getTracks();
res.json(allTracks);
});
// Sitemap endpoint
app.get('/sitemap.xml', async (req, res) => {
const allTracks = await getTracks();
let sitemap = `<?xml version="1.0" encoding="UTF-8"?>\n`;
sitemap += `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n`;
// Home page
sitemap += `<url>\n <loc>https://raven-scott.rocks/</loc>\n <priority>1.0</priority>\n</url>\n`;
// Track pages
allTracks.forEach(track => {
sitemap += `<url>\n <loc>https://raven-scott.rocks/track/${track.slug}</loc>\n <priority>0.8</priority>\n</url>\n`;
});
sitemap += `</urlset>`;
res.header('Content-Type', 'application/xml');
res.send(sitemap);
});
// Listen on the specified port // Listen on the specified port
app.listen(PORT, () => { app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`); console.log(`Server is running on port ${PORT}`);