diff --git a/controllers/resources.js b/controllers/resources.js index a9edf03480..d9e9450c6f 100644 --- a/controllers/resources.js +++ b/controllers/resources.js @@ -49,53 +49,77 @@ module.exports = { async.parallel({ + users: function(callback) { + User.aggregate() + .group({_id: 1, usernames: { $addToSet: '$profile.username'}}) + .match({'profile.username': { $ne: ''}}) + .exec(function(err, users) { + if (err) { + debug('User err: ', err); + callback(err); + } else { + callback(null, users[0].usernames); + } + }); + }, + challenges: function (callback) { - Courseware.find({}, function (err, challenges) { - if (err) { - debug('Courseware err: ', err); - callback(err); - } else { - callback(null, challenges); - } - }); + Courseware.aggregate() + .group({_id: 1, names: { $addToSet: '$name'}}) + .exec(function (err, challenges) { + if (err) { + debug('Courseware err: ', err); + callback(err); + } else { + callback(null, challenges[0].names); + } + }); }, bonfires: function (callback) { - Bonfire.find({}, function (err, bonfires) { + Bonfire.aggregate() + .group({_id: 1, names: { $addToSet: '$name'}}) + .exec(function (err, bonfires) { if (err) { debug('Bonfire err: ', err); callback(err); } else { - callback(null, bonfires); + callback(null, bonfires[0].names); } }); }, stories: function (callback) { - Story.find({}, function (err, stories) { + Story.aggregate() + .group({_id: 1, links: {$addToSet: '$link'}}) + .exec(function (err, stories) { if (err) { debug('Story err: ', err); callback(err); } else { - callback(null, stories); + callback(null, stories[0].links); } }); }, nonprofits: function (callback) { - Nonprofit.find({}, function (err, nonprofits) { + Nonprofit.aggregate() + .group({_id: 1, names: { $addToSet: '$name'}}) + .exec(function (err, nonprofits) { if (err) { debug('User err: ', err); callback(err); } else { - callback(null, nonprofits); + callback(null, nonprofits[0].names); } }); }, fieldGuides: function (callback) { - FieldGuide.find({}, function (err, fieldGuides) { + FieldGuide.aggregate() + .group({_id: 1, names: { $addToSet: '$name'}}) + .exec(function (err, fieldGuides) { if (err) { debug('User err: ', err); callback(err); } else { - callback(null, fieldGuides); + callback(null, fieldGuides[0].names); } }); } @@ -108,6 +132,7 @@ module.exports = { res.render('resources/sitemap', { appUrl: appUrl, now: now, + users: results.users, challenges: results.challenges, bonfires: results.bonfires, stories: results.stories, @@ -371,7 +396,6 @@ module.exports = { })(); }, - // todo analyze this function in detail updateUserStoryPictures: function(userId, picture, username, cb) { var counter = 0, diff --git a/views/resources/sitemap.jade b/views/resources/sitemap.jade index c40a4c9cfb..7d7c7b1c1c 100644 --- a/views/resources/sitemap.jade +++ b/views/resources/sitemap.jade @@ -32,10 +32,19 @@ urlset(xmlns="http://www.sitemaps.org/schemas/sitemap/0.9") changefreq daily priority= 0.8 + //- User + each user in users + url + loc #{appUrl}/#{user} + lastmod= now + changefreq daily + priority= 0.9 + + //- Products each bonfire in bonfires url - loc #{appUrl}/bonfires/#{bonfire.name.replace(/\s/g, '-')} + loc #{appUrl}/bonfires/#{bonfire.replace(/\s/g, '-')} lastmod= now changefreq weekly priority= 0.5 @@ -43,7 +52,7 @@ urlset(xmlns="http://www.sitemaps.org/schemas/sitemap/0.9") //- Challenges each challenge in challenges url - loc #{appUrl}/challenges/#{challenge.name.replace(/\s/g, '-')} + loc #{appUrl}/challenges/#{challenge.replace(/\s/g, '-')} lastmod= now changefreq weekly priority= 0.5 @@ -51,7 +60,7 @@ urlset(xmlns="http://www.sitemaps.org/schemas/sitemap/0.9") //- Stories each story in stories url - loc #{appUrl}/stories/#{story.storyLink.replace(/\s/g, '-')} + loc #{appUrl}/stories/#{story.replace(/\s/g, '-')} lastmod= now changefreq daily priority= 0.9 @@ -59,7 +68,7 @@ urlset(xmlns="http://www.sitemaps.org/schemas/sitemap/0.9") //- Nonprofit each nonprofit in nonprofits url - loc #{appUrl}/nonprofits/#{nonprofit.name.replace(/\s/g, '-')} + loc #{appUrl}/nonprofits/#{nonprofit.replace(/\s/g, '-')} lastmod= now changefreq daily priority= 0.9 @@ -67,7 +76,7 @@ urlset(xmlns="http://www.sitemaps.org/schemas/sitemap/0.9") //- Nonprofit each fieldGuide in fieldGuides url - loc #{appUrl}/field-guide/#{fieldGuide.name.replace(/\s/g, '-')} + loc #{appUrl}/field-guide/#{fieldGuide.replace(/\s/g, '-')} lastmod= now changefreq daily priority= 0.9