sitemap-generator-custom-volodzya
Advanced tools
Comparing version 1.0.3 to 1.0.4
{ | ||
"name": "sitemap-generator-custom-volodzya", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "A library to generate sitemaps in various formats", | ||
@@ -5,0 +5,0 @@ "main": "src/SitemapGenerator.js", |
@@ -7,11 +7,36 @@ const fs = require('fs'); | ||
class SitemapGenerator { | ||
constructor(pages, fileType, filePath) { | ||
this.validatePages(pages); | ||
this.pages = pages; | ||
constructor(basePath, fileType, filePath) { | ||
this.basePath = basePath; | ||
this.fileType = fileType; | ||
this.filePath = filePath; | ||
this.pages = this.getPages(this.basePath); | ||
this.validatePages(this.pages); | ||
this.generateSitemap(); | ||
} | ||
getPages(dir, baseURL = '') { | ||
let pages = []; | ||
const files = fs.readdirSync(dir); | ||
files.forEach(file => { | ||
const fullPath = path.join(dir, file); | ||
const stat = fs.statSync(fullPath); | ||
if (stat.isDirectory()) { | ||
pages = pages.concat(this.getPages(fullPath, path.join(baseURL, file))); | ||
} else if (file.endsWith('.html')) { | ||
pages.push({ | ||
loc: path.join(baseURL, file).replace(/\\/g, '/'), | ||
lastmod: stat.mtime.toISOString().split('T')[0], | ||
changefreq: 'daily', | ||
priority: '0.5' | ||
}); | ||
} | ||
}); | ||
return pages; | ||
} | ||
validatePages(pages) { | ||
@@ -18,0 +43,0 @@ for (const page of pages) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5751
126