import fs from 'fs'; import { globby } from 'globby'; import prettier from 'prettier'; import path from 'path'; async function generate() { const prettierConfig = await prettier.resolveConfig('./.prettierrc'); // Ensure directories exist fs.mkdirSync('public', { recursive: true }); fs.mkdirSync('out', { recursive: true }); // Get static pages const pages = await globby([ 'app/**/page.tsx', '!app/**/_*/**', '!app/**/api/**', '!app/docs/**', // Exclude docs directory as we'll handle it separately ]); // Get doc pages from the build output const docPages = await globby(['out/docs/**/*.html']) .then(pages => pages .map(page => page .replace('out', '') .replace('/index.html', '') .replace('.html', '') ) .filter(page => !page.includes('/_')) ); // Get blog pages from the build output const blogPages = await globby(['out/blog/**/*.html']) .then(pages => pages .map(page => page .replace('out', '') .replace('/index.html', '') .replace('.html', '') ) .filter(page => !page.includes('/_') && !page.includes('/blog/index')) ); const baseUrl = 'https://amical.ai'; const sitemap = ` ${[ // Add static pages ...pages.map((page) => { const path = page .replace('app', '') .replace('/page.tsx', '') .replace('/(home)', '') .replace(/\[\[\.\.\..*?\]\]/, ''); // Skip dynamic routes with parameters if (path.includes('[') || path.includes(']')) { return ''; } const route = path === '' ? '' : path; return ` ${baseUrl}${route} ${new Date().toISOString()} daily 0.7 `; }), // Add docs index page ` ${baseUrl}/docs ${new Date().toISOString()} daily 0.7 `, // Add doc pages ...docPages.map((path) => ` ${baseUrl}${path} ${new Date().toISOString()} daily 0.7 `), // Add blog index page ` ${baseUrl}/blog ${new Date().toISOString()} weekly 0.8 `, // Add blog pages ...blogPages.map((path) => ` ${baseUrl}${path} ${new Date().toISOString()} weekly 0.7 `), ] .filter(Boolean) .join('')} `; const formatted = await prettier.format(sitemap, { ...prettierConfig, parser: 'html', }); fs.writeFileSync('public/sitemap.xml', formatted); fs.writeFileSync('out/sitemap.xml', formatted); console.log('✅ Generated sitemap.xml'); } generate().catch((err) => { console.error(err); process.exit(1); });