gulp-sitemap
Advanced tools
Comparing version 4.0.0 to 4.1.0
@@ -58,4 +58,4 @@ 'use strict'; | ||
} | ||
var mtime = file.stat ? file.stat.mtime : null; | ||
var entry = sitemap.getEntryConfig(file.relative, mtime, config); | ||
var entry = sitemap.getEntryConfig(file, config); | ||
entries.push(entry); | ||
@@ -62,0 +62,0 @@ callback(); |
@@ -9,3 +9,2 @@ 'use strict'; | ||
//TODO: export this to an external module | ||
var header = [ | ||
@@ -16,22 +15,32 @@ '<?xml version="1.0" encoding="UTF-8"?>', | ||
var headerHref = [ | ||
'<?xml version="1.0" encoding="UTF-8"?>', | ||
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">' | ||
]; | ||
var footer = ['</urlset>']; | ||
var allowedProperties = ['getLoc', 'lastmod', 'priority', 'changefreq', 'hreflang']; | ||
function getEntryConfig(file, fileLastMod, siteConfig) { | ||
function getEntryConfig(file, siteConfig) { | ||
var relativePath = file.relative; | ||
var mappingsForFile = find(siteConfig.mappings, function(item) { | ||
return multimatch(file, item.pages).length > 0; | ||
return multimatch(relativePath, item.pages).length > 0; | ||
}) || {}; | ||
var properties = ['getLoc', 'lastmod', 'priority', 'changefreq', 'hreflang']; | ||
var entry = defaults( | ||
pick(mappingsForFile, properties), | ||
pick(siteConfig, properties) | ||
{}, | ||
pick(mappingsForFile, allowedProperties), | ||
pick(siteConfig, allowedProperties) | ||
); | ||
if (entry.lastmod === null) { | ||
entry.lastmod = fileLastMod || Date.now(); | ||
// calculate mtime manually | ||
entry.lastmod = file.stat && file.stat.mtime || Date.now(); | ||
} else if (typeof entry.lastmod === 'function') { | ||
entry.lastmod = entry.lastmod(file); | ||
} | ||
const indexRegex = /(\/|^)index\.html?$/; | ||
//turn index.html into -> / | ||
var relativeFile = file.replace(/(\/index\.html?|^index\.html?)$/, function(string, match) { | ||
var relativeFile = relativePath.replace(indexRegex, function(string, match) { | ||
return match.slice(0, 1) === '/' ? '/' : ''; | ||
@@ -55,3 +64,3 @@ }, 'i'); | ||
* @param entry | ||
* @param config | ||
* @param siteConfig | ||
* @return {Array} | ||
@@ -97,3 +106,6 @@ */ | ||
function prepareSitemap(entries, config) { | ||
return header | ||
var entriesHref = entries.some(function(entry) { | ||
return entry && entry.hreflang && entry.hreflang.length; | ||
}); | ||
return (entriesHref ? headerHref : header) | ||
.concat(entries.map(function(entry) { | ||
@@ -100,0 +112,0 @@ return processEntry(entry, config); |
{ | ||
"name": "gulp-sitemap", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "Generate a search engine friendly sitemap.xml using a Gulp stream", | ||
@@ -5,0 +5,0 @@ "repository": "pgilad/gulp-sitemap", |
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
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
189
8805
4
1
0