From 4ca87f63362e7b35634d1faf2a86a9073b5f274c Mon Sep 17 00:00:00 2001 From: cobbspur Date: Sun, 14 Dec 2014 23:03:40 +0000 Subject: [PATCH] Fixes sitemap image errors closes #4591 - switches to using author cover image - adds a protocol of http if using a protocol relative url --- core/server/data/sitemap/user-generator.js | 36 ++++++++++++---------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/core/server/data/sitemap/user-generator.js b/core/server/data/sitemap/user-generator.js index 3089596465..c8f08cbfaf 100644 --- a/core/server/data/sitemap/user-generator.js +++ b/core/server/data/sitemap/user-generator.js @@ -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;