11// next-sitemap.config.js
22// File path: next-sitemap.config.js
3- // Configures sitemap for K12Beast, including only root and public pages
4- // Scans directories for page.tsx and page.mdx files , excluding dynamic routes and non-public paths
3+ // Configures sitemap for K12Beast, including only root and / public/* pages
4+ // Scans src/app/public for page.tsx and src/content/docs for page.mdx, excluding all other routes
55
66const fs = require ( 'fs' ) ;
77const path = require ( 'path' ) ;
88
99const PUBLIC_DIR = path . join ( process . cwd ( ) , 'src/app/public' ) ;
1010const DOCS_DIR = path . join ( process . cwd ( ) , 'src/content/docs' ) ;
1111
12- function addPaths ( dir , prefix , fileName ) {
12+ function getPublicPaths ( dir , prefix , fileName ) {
13+ console . log ( `[Sitemap Config] Scanning directory: ${ dir } ` ) ;
1314 const paths = [ ] ;
15+ if ( ! fs . existsSync ( dir ) ) {
16+ console . log ( `[Sitemap Config] Directory not found: ${ dir } ` ) ;
17+ return paths ;
18+ }
1419 fs . readdirSync ( dir ) . forEach ( file => {
1520 const filePath = path . join ( dir , file ) ;
1621 if ( fs . statSync ( filePath ) . isDirectory ( ) ) {
17- paths . push ( ...addPaths ( filePath , `${ prefix } /${ file } ` , fileName ) ) ;
22+ paths . push ( ...getPublicPaths ( filePath , `${ prefix } /${ file } ` , fileName ) ) ;
1823 } else if ( file === fileName ) {
1924 const relativePath = prefix . endsWith ( '/public' ) ? '/public' : prefix ;
20- // Exclude dynamic routes and non- public paths
25+ // Only include paths starting with / public/ or /public
2126 if ( ! relativePath . includes ( '[' ) && ( relativePath === '/public' || relativePath . startsWith ( '/public/' ) ) ) {
27+ console . log ( `[Sitemap Config] Including path: ${ relativePath } ` ) ;
2228 paths . push ( {
2329 loc : relativePath ,
2430 lastmod : new Date ( ) . toISOString ( ) ,
2531 changefreq : 'daily' ,
2632 priority : relativePath === '/public' ? 0.8 : 0.7 ,
2733 } ) ;
34+ } else {
35+ console . log ( `[Sitemap Config] Excluding path: ${ relativePath } ` ) ;
2836 }
2937 }
3038 } ) ;
@@ -35,7 +43,11 @@ module.exports = {
3543 siteUrl : 'https://k12beast.com' ,
3644 generateRobotsTxt : true ,
3745 generateIndexSitemap : false ,
46+ // Prevent automatic inclusion of src/app routes
47+ exclude : [ '/*' ] , // Exclude all routes by default
3848 additionalPaths : async ( ) => {
49+ console . log ( '[Sitemap Config] Generating sitemap paths' ) ;
50+ console . log ( `[Sitemap Config] Environment: CI=${ process . env . CI || 'false' } ` ) ;
3951 const paths = [
4052 {
4153 loc : '/' ,
@@ -44,8 +56,10 @@ module.exports = {
4456 priority : 1.0 ,
4557 } ,
4658 ] ;
47- paths . push ( ...addPaths ( PUBLIC_DIR , '/public' , 'page.tsx' ) ) ;
48- paths . push ( ...addPaths ( DOCS_DIR , '/public/docs' , 'page.mdx' ) ) ;
59+ // Include all /public/* paths
60+ paths . push ( ...getPublicPaths ( PUBLIC_DIR , '/public' , 'page.tsx' ) ) ;
61+ paths . push ( ...getPublicPaths ( DOCS_DIR , '/public/docs' , 'page.mdx' ) ) ;
62+ console . log ( `[Sitemap Config] Total paths generated: ${ paths . length } ` ) ;
4963 return paths ;
5064 } ,
5165} ;
0 commit comments