<commit_before>'use strict';

var async = require('async'),
    fs = require('fs'),
    fse = require('fs-extra'),
    path = require('path'),
    config = require('../config.js');

function getLocations(slug, opts){
    var relative = opts.config.physical(slug),
        physical = path.join(config.statics.bin, relative),
        folder = path.dirname(physical);

    return {
        relative: relative,
        physical: physical,
        folder: folder
    };
}

function filter(req, opts){
    if(opts.requireMarket === true && req.blogStatus === 'market'){
        return false;
    }
    return !req.blog; // next() on non-blog
}

function getMetaXml(opts){
    return function(req,res,next){
        if(filter(req,opts)){
            return next();
        }

        var loc = getLocations(req.blog.slug, opts);

        fse.mkdirs(loc.folder, function(err){
            if(err){
                throw err;
            }

            fs.exists(loc.physical, function(exists){
                if(exists){
                    fs.stat(loc.physical,function(err, stats){
                        var now = new Date();
                        if (now - stats.mtime > opts.config.cache){
                            return opts.setup(req, serve(res));
                        }else{
                            return serve(res)(null,null,loc.physical);
                        }
                    });
                }else{
                    return opts.setup(req, serve(res));
                }
            });
        });
    };
}

function serve(res){
    return function(err,xml,physical){
        if(err){<commit_msg>sitemap index only on market<commit_after>'use strict';

var async = require('async'),
    fs = require('fs'),
    fse = require('fs-extra'),
    path = require('path'),
    config = require('../config.js');

function getLocations(slug, opts){
    var relative = opts.config.physical(slug),
        physical = path.join(config.statics.bin, relative),
        folder = path.dirname(physical);

    return {
        relative: relative,
        physical: physical,
        folder: folder
    };
}

function filter(req, opts){
    if(opts.requireMarket === true){
        return req.blogStatus !== 'market';
    }
    return !req.blog; // next() on non-blog
}

function getMetaXml(opts){
    return function(req,res,next){
        if(filter(req,opts)){
            return next();
        }

        var loc = getLocations(req.slug, opts);

        fse.mkdirs(loc.folder, function(err){
            if(err){
                throw err;
            }

            fs.exists(loc.physical, function(exists){
                if(exists){
                    fs.stat(loc.physical,function(err, stats){
                        var now = new Date();
                        if (now - stats.mtime > opts.config.cache){
                            return opts.setup(req, serve(res));
                        }else{
                            return serve(res)(null,null,loc.physical);
                        }
                    });
                }else{
                    return opts.setup(req, serve(res));
                }
            });
        });
    };
}

function serve(res){
    return function(err,xml,physical){
        if(err){
{'fraction_non_alphanumeric': 0.13462128181539404, 'fraction_numerical': 0.0, 'mean_word_length': 1.5326086956521738, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '4001445', 'n_tokens_mistral': 912, 'n_tokens_neox': 871, 'n_words': 180}