@@ -15,7 +15,7 @@ class EnhancedSitemapGenerator {
1515 // Generate main sitemap
1616 generateMainSitemap ( ) {
1717 console . log ( '🚀 Generating enhanced main sitemap...' ) ;
18-
18+
1919 // Add core pages with proper priorities and change frequencies
2020 this . addUrl ( '/' , '1.0' , 'weekly' , 'Homepage' ) ;
2121 this . addUrl ( '/about.html' , '0.8' , 'monthly' , 'About Page' ) ;
@@ -24,49 +24,48 @@ class EnhancedSitemapGenerator {
2424 this . addUrl ( '/images.html' , '0.9' , 'weekly' , 'Images Page' ) ;
2525 this . addUrl ( '/partners.html' , '0.8' , 'monthly' , 'Partners Page' ) ;
2626 this . addUrl ( '/documents/index.html' , '0.9' , 'weekly' , 'Documents Index' ) ;
27-
27+
2828 // Add category landing pages
2929 this . addCategoryPages ( ) ;
30-
30+
3131 // Add individual document pages
3232 this . addDocumentPages ( ) ;
33-
33+
3434 // Generate the sitemap XML
3535 const sitemapXml = this . generateSitemapXml ( ) ;
36- fs . writeFileSync ( ' sitemap.xml', sitemapXml ) ;
36+ fs . writeFileSync ( path . join ( __dirname , '..' , ' sitemap.xml') , sitemapXml ) ;
3737 console . log ( `✅ Main sitemap generated with ${ this . sitemapUrls . length } URLs` ) ;
38-
38+
3939 return this . sitemapUrls ;
4040 }
4141
4242 // Generate image sitemap
4343 generateImageSitemap ( ) {
4444 console . log ( '🖼️ Generating image sitemap...' ) ;
45-
45+
4646 // Add images from the images directory
4747 this . addImagesFromDirectory ( ) ;
48-
48+
4949 // Generate the image sitemap XML
5050 const imageSitemapXml = this . generateImageSitemapXml ( ) ;
51- fs . writeFileSync ( ' sitemap-images.xml', imageSitemapXml ) ;
51+ fs . writeFileSync ( path . join ( __dirname , '..' , ' sitemap-images.xml') , imageSitemapXml ) ;
5252 console . log ( `✅ Image sitemap generated with ${ this . imageSitemapUrls . length } URLs` ) ;
53-
53+
5454 return this . imageSitemapUrls ;
5555 }
5656
5757 // Generate video sitemap
5858 generateVideoSitemap ( ) {
5959 console . log ( '🎥 Generating video sitemap...' ) ;
60-
60+
6161 // Add videos from videos.yaml
6262 this . addVideosFromYaml ( ) ;
63-
63+
6464 // Generate the video sitemap XML
6565 const videoSitemapXml = this . generateVideoSitemapXml ( ) ;
66- fs . writeFileSync ( 'sitemap-videos.xml' , videoSitemapXml ) ;
67- fs . writeFileSync ( 'sitemap-videos.xml' , videoSitemapXml ) ;
66+ fs . writeFileSync ( path . join ( __dirname , '..' , 'sitemap-videos.xml' ) , videoSitemapXml ) ;
6867 console . log ( `✅ Video sitemap generated with ${ this . videoSitemapUrls . length } URLs` ) ;
69-
68+
7069 return this . videoSitemapUrls ;
7170 }
7271
@@ -111,14 +110,14 @@ class EnhancedSitemapGenerator {
111110 // Add document pages from YAML
112111 addDocumentPages ( ) {
113112 try {
114- const documentsYaml = fs . readFileSync ( ' content/ documents.yaml', 'utf8' ) ;
113+ const documentsYaml = fs . readFileSync ( path . join ( __dirname , '..' , ' content' , ' documents.yaml') , 'utf8' ) ;
115114 const documents = yaml . load ( documentsYaml ) ;
116-
115+
117116 if ( documents && documents . documents ) {
118117 documents . documents . forEach ( doc => {
119118 const docPath = `/documents/${ doc . id } .html` ;
120119 this . addUrl ( docPath , '0.8' , 'monthly' , doc . title ) ;
121-
120+
122121 // Add related documents for internal linking
123122 if ( doc . relatedDocuments ) {
124123 doc . relatedDocuments . forEach ( related => {
@@ -137,7 +136,7 @@ class EnhancedSitemapGenerator {
137136
138137 // Add images from directory
139138 addImagesFromDirectory ( ) {
140- const imagesDir = ' images';
139+ const imagesDir = path . join ( __dirname , '..' , ' images') ;
141140 if ( fs . existsSync ( imagesDir ) ) {
142141 const imageFiles = this . getImageFiles ( imagesDir ) ;
143142 imageFiles . forEach ( image => {
@@ -156,12 +155,12 @@ class EnhancedSitemapGenerator {
156155 getImageFiles ( dir , baseDir = '' ) {
157156 const files = [ ] ;
158157 const items = fs . readdirSync ( dir ) ;
159-
158+
160159 items . forEach ( item => {
161160 const fullPath = path . join ( dir , item ) ;
162161 const relativePath = path . join ( baseDir , item ) ;
163162 const stat = fs . statSync ( fullPath ) ;
164-
163+
165164 if ( stat . isDirectory ( ) ) {
166165 files . push ( ...this . getImageFiles ( fullPath , relativePath ) ) ;
167166 } else if ( this . isImageFile ( item ) ) {
@@ -174,7 +173,7 @@ class EnhancedSitemapGenerator {
174173 } ) ;
175174 }
176175 } ) ;
177-
176+
178177 return files ;
179178 }
180179
@@ -200,9 +199,9 @@ class EnhancedSitemapGenerator {
200199 // Add videos from YAML
201200 addVideosFromYaml ( ) {
202201 try {
203- const videosYaml = fs . readFileSync ( ' content/ videos.yaml', 'utf8' ) ;
202+ const videosYaml = fs . readFileSync ( path . join ( __dirname , '..' , ' content' , ' videos.yaml') , 'utf8' ) ;
204203 const videos = yaml . load ( videosYaml ) ;
205-
204+
206205 if ( videos && videos . videos ) {
207206 videos . videos . forEach ( video => {
208207 this . videoSitemapUrls . push ( {
@@ -228,7 +227,7 @@ class EnhancedSitemapGenerator {
228227 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
229228 xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
230229 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">\n\n` ;
231-
230+
232231 this . sitemapUrls . forEach ( url => {
233232 xml += ` <url>
234233 <loc>${ url . loc } </loc>
@@ -237,7 +236,7 @@ class EnhancedSitemapGenerator {
237236 <priority>${ url . priority } </priority>
238237 </url>\n` ;
239238 } ) ;
240-
239+
241240 xml += '\n</urlset>' ;
242241 return xml ;
243242 }
@@ -247,7 +246,7 @@ class EnhancedSitemapGenerator {
247246 let xml = `<?xml version="1.0" encoding="UTF-8"?>
248247<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
249248 xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">\n\n` ;
250-
249+
251250 this . imageSitemapUrls . forEach ( url => {
252251 xml += ` <url>
253252 <loc>${ url . loc } </loc>
@@ -259,7 +258,7 @@ class EnhancedSitemapGenerator {
259258 </image:image>
260259 </url>\n` ;
261260 } ) ;
262-
261+
263262 xml += '\n</urlset>' ;
264263 return xml ;
265264 }
@@ -269,7 +268,7 @@ class EnhancedSitemapGenerator {
269268 let xml = `<?xml version="1.0" encoding="UTF-8"?>
270269<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
271270 xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">\n\n` ;
272-
271+
273272 this . videoSitemapUrls . forEach ( url => {
274273 xml += ` <url>
275274 <loc>${ url . loc } </loc>
@@ -283,7 +282,7 @@ class EnhancedSitemapGenerator {
283282 </video:video>
284283 </url>\n` ;
285284 } ) ;
286-
285+
287286 xml += '\n</urlset>' ;
288287 return xml ;
289288 }
@@ -305,20 +304,20 @@ class EnhancedSitemapGenerator {
305304 <lastmod>${ this . currentDate } </lastmod>
306305 </sitemap>
307306</sitemapindex>` ;
308-
309- fs . writeFileSync ( ' sitemap-index.xml', sitemapIndex ) ;
307+
308+ fs . writeFileSync ( path . join ( __dirname , '..' , ' sitemap-index.xml') , sitemapIndex ) ;
310309 console . log ( '✅ Sitemap index generated' ) ;
311310 }
312311
313312 // Generate all sitemaps
314313 generateAll ( ) {
315314 console . log ( '🚀 Starting enhanced sitemap generation...\n' ) ;
316-
315+
317316 this . generateMainSitemap ( ) ;
318317 this . generateImageSitemap ( ) ;
319318 this . generateVideoSitemap ( ) ;
320319 this . generateSitemapIndex ( ) ;
321-
320+
322321 console . log ( '\n🎉 All sitemaps generated successfully!' ) ;
323322 console . log ( '\n📊 Sitemap Summary:' ) ;
324323 console . log ( ` Main Sitemap: ${ this . sitemapUrls . length } URLs` ) ;
0 commit comments