File tree Expand file tree Collapse file tree 4 files changed +35
-6
lines changed Expand file tree Collapse file tree 4 files changed +35
-6
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,10 @@ checkHttpStatus({
3939 ' Accept' : ' text/html' ,
4040 },
4141 },
42- ' sitemap' : ' https://www.trunkcode.com/page-sitemap.xml' ,
42+ ' sitemap' : [
43+ ' https://www.trunkcode.com/page-sitemap.xml' ,
44+ ' https://www.trunkcode.com/post-sitemap.xml'
45+ ],
4346 ' skip200' : true , // Do not report the URLs having HTTP code 200.
4447});
4548```
Original file line number Diff line number Diff line change 11'use strict' ;
22
33const consoleColumns = require ( './lib/console-columns' ) ;
4- const fetchFromSitemap = require ( './lib/fetch-from-sitemap' ) ;
4+ const fetchAllSitemaps = require ( './lib/fetch-from-sitemap' ) ;
55const fs = require ( 'fs' ) ;
66const generateExcel = require ( './lib/generate-excel' ) ;
77const httpList = require ( './lib/http-list' ) ;
@@ -30,7 +30,7 @@ async function checkHttpStatus(config) {
3030 }
3131
3232 if ( config . sitemap ) {
33- urlsList = await fetchFromSitemap ( config . sitemap ) ;
33+ urlsList = await fetchAllSitemaps ( config . sitemap ) ;
3434 } else if ( config . urls && Array . isArray ( config . urls ) ) {
3535 urlsList = config . urls ;
3636 }
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ const xml2js = require('xml2js');
77 * Fetch Sitemap URL and dumb all the URLs from the XML to a variable.
88 */
99function fetchFromSitemap ( sitemapUrl ) {
10- var errorMessage = 'Error: Sitemap URL returns with status code ' ;
10+ var errorMessage = 'Error: ' + sitemapUrl + ' returns with status code ';
1111 var fetchedUrls = [ ] ;
1212
1313 return new Promise ( ( resolve ) => {
@@ -42,4 +42,27 @@ function fetchFromSitemap(sitemapUrl) {
4242 } ) ;
4343}
4444
45- module . exports = fetchFromSitemap ;
45+ async function fetchAllSitemaps ( sitemapUrls ) {
46+ const sitemapUrlsLists = [ ] ;
47+ const urlsList = [ ] ;
48+
49+ var mergeLists = [ ] ;
50+ for ( const sitemapUrl of sitemapUrls ) {
51+ sitemapUrlsLists . push ( fetchFromSitemap ( sitemapUrl ) ) ;
52+ }
53+
54+ const allUrls = await Promise . all ( sitemapUrlsLists ) ;
55+ for ( const singleList of allUrls ) {
56+ mergeLists = mergeLists . concat ( singleList ) ;
57+ }
58+
59+ for ( const singleUrl of mergeLists ) {
60+ if ( ! urlsList . includes ( singleUrl ) ) {
61+ urlsList . push ( singleUrl ) ;
62+ }
63+ }
64+
65+ return urlsList ;
66+ }
67+
68+ module . exports = fetchAllSitemaps ;
Original file line number Diff line number Diff line change @@ -16,6 +16,9 @@ checkHttpStatus({
1616 'Accept' : 'text/html' ,
1717 } ,
1818 } ,
19- 'sitemap' : 'https://www.trunkcode.com/page-sitemap.xml' ,
19+ 'sitemap' : [
20+ 'https://www.trunkcode.com/page-sitemap.xml' ,
21+ 'https://www.trunkcode.com/post-sitemap.xml'
22+ ] ,
2023 'skip200' : true ,
2124} ) ;
You can’t perform that action at this time.
0 commit comments