Skip to content

Commit

Permalink
Fixes sitemap image errors
Browse files Browse the repository at this point in the history
closes #4591

- switches to using author cover image
- adds a protocol of http if using a protocol relative url
  • Loading branch information
cobbspur committed Dec 14, 2014
1 parent 4c3d548 commit 4ca87f6
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions core/server/data/sitemap/user-generator.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4ca87f6

Please sign in to comment.