gulp-sitemap
Advanced tools
Comparing version 6.2.0 to 7.0.0
'use strict'; | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const defaults = require('lodash/defaults'); | ||
@@ -34,2 +36,7 @@ const find = require('lodash/find'); | ||
// if images enabled add headerHref | ||
if (siteConfig.images) { | ||
headerHref[1] = '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">' | ||
} | ||
if (entry.lastmod === null) { | ||
@@ -51,2 +58,3 @@ // calculate mtime manually | ||
entry.file = adjustedFile; | ||
entry.source = file.history[0]; | ||
@@ -57,5 +65,52 @@ return entry; | ||
function wrapTag(tag, value) { | ||
return '<' + tag + '>' + value + '</' + tag + '>'; | ||
return ` | ||
<${ tag }>${ value }</${ tag }> | ||
`; | ||
} | ||
function createImageSitemap(imageURL) { | ||
return ` | ||
<image:image> | ||
<image:loc>${imageURL}</image:loc> | ||
</image:image> | ||
`; | ||
} | ||
function notIsHTTPURL(text) { | ||
return !(/https?:\/\//ig).test(text); | ||
} | ||
function getImagesUrl(entry, siteConfig) { | ||
const reImageMatch = /<img\s+src="((https?:\/\/)?[\w\.\/]+)"\s+alt="[\w\.a/]*"\/?>/ig; | ||
const reSourceMatch = /"((https?:\/\/)?[\w\.\/]+)"/ig; | ||
const html = fs.readFileSync(entry.source, { encoding : 'utf8'}); | ||
const URLs = html.match(reImageMatch).map(image => { | ||
let currentURL = image.match(reSourceMatch)[0].replace(/^\"|\"$/ig, ''); | ||
if (notIsHTTPURL(currentURL)) { | ||
currentURL = currentURL.replace(/^\/|\.\//, ''); | ||
currentURL = siteConfig.siteUrl + currentURL; | ||
} | ||
return currentURL; | ||
}); | ||
return URLs; | ||
} | ||
function generateImagesMap(entry, siteConfig) { | ||
let imagesURLS = []; | ||
let XMLImageList = ''; | ||
// Crawling page for images | ||
imagesURLS = getImagesUrl(entry, siteConfig); | ||
// if truthy create image sitemap | ||
if (imagesURLS.length) { | ||
XMLImageList = imagesURLS.map(imageURL => createImageSitemap(imageURL)).join('') | ||
} | ||
return XMLImageList; | ||
} | ||
/** | ||
@@ -72,3 +127,3 @@ * processEntry | ||
const loc = entry.getLoc ? entry.getLoc(siteConfig.siteUrl, entry.loc, entry) : entry.loc; | ||
returnArr.push(siteConfig.spacing + siteConfig.spacing + wrapTag('loc', loc)); | ||
returnArr.push(siteConfig.spacing + siteConfig.spacing + wrapTag('loc', loc) + (siteConfig.images ? generateImagesMap(entry, siteConfig) : '')); | ||
@@ -75,0 +130,0 @@ let lastmod = entry.lastmod; |
{ | ||
"name": "gulp-sitemap", | ||
"version": "6.2.0", | ||
"version": "7.0.0", | ||
"description": "Generate a search engine friendly sitemap.xml using a Gulp stream", | ||
"repository": "pgilad/gulp-sitemap", | ||
"license": "MIT", | ||
"author": { | ||
"name": "Gilad Peleg", | ||
"email": "giladp007@gmail.com", | ||
"url": "http://giladpeleg.com" | ||
}, | ||
"author": "Gilad Peleg <gilad@giladpeleg.com> (https://www.giladpeleg.com)", | ||
"main": "index.js", | ||
@@ -18,3 +14,3 @@ "files": [ | ||
"engines": { | ||
"node": ">=6.14.4" | ||
"node": ">=8" | ||
}, | ||
@@ -40,15 +36,15 @@ "scripts": { | ||
"lodash": "^4.17.11", | ||
"multimatch": "^3.0.0", | ||
"multimatch": "^4.0.0", | ||
"plugin-error": "^1.0.1", | ||
"slash": "^2.0.0", | ||
"through2": "^3.0.0", | ||
"slash": "^3.0.0", | ||
"through2": "^3.0.1", | ||
"vinyl": "^2.2.0" | ||
}, | ||
"devDependencies": { | ||
"gulp": "^4.0.0", | ||
"gulp": "^4.0.2", | ||
"gulp-rename": "^1.4.0", | ||
"mocha": "^5.2.0", | ||
"mocha": "^6.1.4", | ||
"should": "^13.2.3", | ||
"strip-ansi": "^5.0.0" | ||
"strip-ansi": "^5.2.0" | ||
} | ||
} |
@@ -171,2 +171,14 @@ # [gulp](https://github.com/wearefractal/gulp)-sitemap | ||
### images | ||
For generate sitemap for images per page, just enable images flag to `true` | ||
Type: `boolean` | ||
Default: `undefined` | ||
Required: `false` | ||
### mappings | ||
@@ -273,2 +285,2 @@ | ||
MIT ©[Gilad Peleg](http://giladpeleg.com) | ||
MIT © [Gilad Peleg](https://www.giladpeleg.com) |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
17477
240
285
2
+ Added@types/minimatch@3.0.5(transitive)
+ Addedarray-differ@3.0.0(transitive)
+ Addedarray-union@2.1.0(transitive)
+ Addedarrify@2.0.1(transitive)
+ Addedmultimatch@4.0.0(transitive)
+ Addedslash@3.0.0(transitive)
- Removedarray-differ@2.1.0(transitive)
- Removedarray-union@1.0.2(transitive)
- Removedarray-uniq@1.0.3(transitive)
- Removedarrify@1.0.1(transitive)
- Removedmultimatch@3.0.0(transitive)
- Removedslash@2.0.0(transitive)
Updatedmultimatch@^4.0.0
Updatedslash@^3.0.0
Updatedthrough2@^3.0.1