#!/usr/bin/env node /** * Sitemap generator for Hastebin * Generates sitemap.xml with static pages and MCP discovery endpoint */ const fs = require('fs'); const path = require('path'); // Get base URL from environment or use default const baseUrl = process.env.HASTEBIN_BASE_URL || process.env.HASTEBIN_SITEMAP_URL || 'https://haste.nixc.us'; // Static pages to include in sitemap const pages = [ { loc: '/', changefreq: 'weekly', priority: '1.0', description: 'Homepage - create and share code snippets' }, { loc: '/about', changefreq: 'monthly', priority: '0.8', description: 'About page with documentation and usage instructions' }, { loc: '/.well-known/mcp.json', changefreq: 'monthly', priority: '0.7', description: 'MCP (Model Context Protocol) discovery endpoint for AI assistants' } ]; // Generate sitemap XML function generateSitemap() { const today = new Date().toISOString().split('T')[0]; let xml = '\n'; xml += '\n'; xml += ' \n'; xml += '\n'; for (const page of pages) { xml += ' \n'; xml += ' \n'; xml += ' ' + baseUrl + page.loc + '\n'; xml += ' ' + today + '\n'; xml += ' ' + page.changefreq + '\n'; xml += ' ' + page.priority + '\n'; xml += ' \n'; xml += '\n'; } xml += '\n'; return xml; } // Generate robots.txt content function generateRobotsTxt() { let robots = '# Hastebin robots.txt\n'; robots += '# Updated: ' + new Date().toISOString().split('T')[0] + '\n'; robots += '\n'; robots += 'User-agent: *\n'; robots += '\n'; robots += '# Allow static pages\n'; robots += 'Allow: /$\n'; robots += 'Allow: /about\n'; robots += '\n'; robots += '# Allow MCP discovery for AI assistants and tools\n'; robots += 'Allow: /.well-known/\n'; robots += 'Allow: /.well-known/mcp.json\n'; robots += '\n'; robots += '# Disallow individual pastes (ephemeral content)\n'; robots += 'Disallow: /raw/\n'; robots += 'Disallow: /documents/\n'; robots += '\n'; robots += '# Disallow paste URLs (random keys)\n'; robots += '# Pastes are identified by 10-character alphanumeric keys\n'; robots += 'Disallow: /*.*\n'; robots += '\n'; robots += '# Sitemap location\n'; robots += 'Sitemap: ' + baseUrl + '/sitemap.xml\n'; return robots; } // Main execution const staticDir = path.join(__dirname, '..', 'static'); // Generate and write sitemap.xml const sitemapContent = generateSitemap(); const sitemapPath = path.join(staticDir, 'sitemap.xml'); fs.writeFileSync(sitemapPath, sitemapContent, 'utf8'); console.log('Generated sitemap.xml at', sitemapPath); console.log('Base URL:', baseUrl); console.log('Pages included:', pages.length); // Generate and write robots.txt const robotsContent = generateRobotsTxt(); const robotsPath = path.join(staticDir, 'robots.txt'); fs.writeFileSync(robotsPath, robotsContent, 'utf8'); console.log('Generated robots.txt at', robotsPath); console.log('\nSitemap generation complete!');