0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-13 22:41:32 -05:00

Merge pull request #4636 from cobbspur/sitemap

Fixes sitemap image errors
This commit is contained in:
Hannah Wolfe 2014-12-14 23:27:04 +00:00
commit 9bb3be49d5

View file

@ -1,8 +1,9 @@
var _ = require('lodash'),
path = require('path'),
api = require('../../api'),
BaseMapGenerator = require('./base-generator'),
config = require('../../config');
var _ = require('lodash'),
path = require('path'),
api = require('../../api'),
BaseMapGenerator = require('./base-generator'),
validator = require('validator'),
config = require('../../config');
// A class responsible for generating a sitemap from posts and keeping it updated
function UserMapGenerator(opts) {
@ -45,18 +46,21 @@ _.extend(UserMapGenerator.prototype, {
imageEl;
// Check for image and add it
if (datum.image) {
if (datum.cover) {
// Grab the image url
imageUrl = this.getUrlForImage(datum.image);
// Create the weird xml node syntax structure that is expected
imageEl = [
{'image:loc': imageUrl},
{'image:caption': path.basename(imageUrl)}
];
// Add the node to the url xml node
orig.url.push({
'image:image': imageEl
});
imageUrl = this.getUrlForImage(datum.cover);
imageUrl = imageUrl.substring(0, 2) === '//' ? 'http:' + imageUrl : imageUrl;
if (validator.isURL(imageUrl, {protocols: ['http', 'https'], require_protocol: true})) {
// Create the weird xml node syntax structure that is expected
imageEl = [
{'image:loc': imageUrl},
{'image:caption': path.basename(imageUrl)}
];
// Add the node to the url xml node
orig.url.push({
'image:image': imageEl
});
}
}
return orig;