<commit_before>'use strict';

var render = require('../lib').render
  , config = require('../config')
  , models = require('../models')
  ;

module.exports.init = function(app) {
  app.get('/sitemap.xml', getSitemap);
};

function getSitemap(req, res) {

  // all existing pages
  var pages = [{
    url: '',
    priority: '1.0'
  }, {
    url: '/projects',
    priority: '0.9'
  }, {
    url: '/services',
    priority: '0.9'
  }, {
    url: '/about',
    priority: '0.9'
  }, {
    url: '/contact',
    priority: '0.9'
  }, {
    url: '/blog',
    priority: '0.9'
  }];

  // services pages
  var services = [];

  if (res.locals.footerNavigation.left && res.locals.footerNavigation.left.length) {
    services = services.concat(res.locals.footerNavigation.left);
  }

  if (res.locals.footerNavigation.right && res.locals.footerNavigation.right.length) {
    services = services.concat(res.locals.footerNavigation.right);
  }

  services.forEach(function(service) {
    pages.push({
      url: service.href,
      priority: '0.8'
    });
  });

  // blog posts
  models.Post.find({}, 'slug', {
    sort: {
      publishedAt: -1
    }
  }, function(err, posts) {

    if (!err && posts) {
      posts.forEach(function(post) {
        pages.push({
          url: '/' + config.postsBase + '/' + post.slug,
          priority: '0.5'
        });
      });
    }

    res.setHeader('Content-Type', 'application/xhtml+xml');

    render(res, 'sitemap', {
      baseURL: req.protocol + '://' + req.get('host'),
      pages: pages<commit_msg>fix protocol<commit_after>'use strict';

var render = require('../lib').render
  , config = require('../config')
  , models = require('../models')
  ;

module.exports.init = function(app) {
  app.get('/sitemap.xml', getSitemap);
};

function getSitemap(req, res) {

  // all existing pages
  var pages = [{
    url: '',
    priority: '1.0'
  }, {
    url: '/projects',
    priority: '0.9'
  }, {
    url: '/services',
    priority: '0.9'
  }, {
    url: '/about',
    priority: '0.9'
  }, {
    url: '/contact',
    priority: '0.9'
  }, {
    url: '/blog',
    priority: '0.9'
  }];

  // services pages
  var services = [];

  if (res.locals.footerNavigation.left && res.locals.footerNavigation.left.length) {
    services = services.concat(res.locals.footerNavigation.left);
  }

  if (res.locals.footerNavigation.right && res.locals.footerNavigation.right.length) {
    services = services.concat(res.locals.footerNavigation.right);
  }

  services.forEach(function(service) {
    pages.push({
      url: service.href,
      priority: '0.8'
    });
  });

  // blog posts
  models.Post.find({}, 'slug', {
    sort: {
      publishedAt: -1
    }
  }, function(err, posts) {

    if (!err && posts) {
      posts.forEach(function(post) {
        pages.push({
          url: '/' + config.postsBase + '/' + post.slug,
          priority: '0.5'
        });
      });
    }

    res.setHeader('Content-Type', 'application/xhtml+xml');

    render(res, 'sitemap', {
      baseURL: (req.secure ? 'https' : 'http' ) + '://' + req.get('host'),
      pages: pages
{'fraction_non_alphanumeric': 0.1934648980912326, 'fraction_numerical': 0.010999676480103526, 'mean_word_length': 2.4090407938257994, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4114036', 'n_tokens_mistral': 1086, 'n_tokens_neox': 1069, 'n_words': 186}