Fixes sitemap image errors

closes #4591

- switches to using author cover image
- adds a protocol of http if using a protocol relative url
This commit is contained in:
cobbspur 2014-12-14 23:03:40 +00:00
parent 4c3d548bb3
commit 4ca87f6336

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;