<commit_before>'use strict';

function init({
    processorConfig,
    processorGlobalConfig,
    globalConfig,
}) {
  const config = Object.assign({}, globalConfig, processorGlobalConfig, processorConfig);

  function templateVariables(sitemap, fns, db) {
    const templateVariables = db.get('templateVariables');

    return config.createMapFor
      .map((type) => templateVariables[type].map((content) => content.meta.url))
      .reduce((arr, cur) => [...arr, ...cur], []);
  }

  function createSitemap(domain, urls) {
    const prefix = '<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n';
    const urlsString = urls.map((url) => {
      const urlPrefix = '  <url>\n';
      const loc = `    <loc>${domain}/${url}</loc>\n`;
      const urlSuffix = '  </url>';
      return urlPrefix + loc + urlSuffix;
    }).join('\n');
    const suffix = '\n</urlset>';
    return prefix + urlsString + suffix;
  }

  function process(sitemapWithLocals, helperFns, db) {
    const next = {};
    const domain = config.domain;

    next.writePath = 'sitemap';
    next.contentsToWrite = createSitemap(domain, db.get('templateVariables').sitemap);
    return next;
  }

  function postprocess(sitemap) {
    if (config.productionMode) {
      sitemap.contentsToWrite = sitemap.contentsToWrite.replace(/\n/g, '').replace(/\s\s+/g, '');
      return sitemap;
    }
    return sitemap;
  }<commit_msg>Enhance sitemap decorator to allow priority, lastmod, changefreq<commit_after>'use strict';

function init({
    processorConfig,
    processorGlobalConfig,
    globalConfig,
}) {
  const config = Object.assign({}, globalConfig, processorGlobalConfig, processorConfig);

  function templateVariables(sitemap, fns, db) {
    const templateVariables = db.get('templateVariables');
    return config.createMapFor
      .map((type) => templateVariables[type].map((content) => {
        const contentSiteMapConfig = content.meta.sitemap || {};
        return {
          url: content.meta.url,
          changeFrequency: contentSiteMapConfig.changeFrequency,
          priority: contentSiteMapConfig.priority,
          lastModified: contentSiteMapConfig.lastModified,
        };
      }))
      .reduce((arr, cur) => [...arr, ...cur], []);
  }

  function createEntry(domain, { url, changeFrequency = '', priority = '', lastModified = '' }) {
    return `
    <url>
      <loc>${domain}/${url}</loc>
      <lastmod>${lastModified}</lastmod>
      <changefreq>${changeFrequency}</changefreq>
      <priority>${priority}</priority>
    </url>`;
  }

  function createSitemap(domain, entries) {
    return `<?xml version="1.0" encoding="UTF-8"?>
      <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
        ${entries.map((entry) => createEntry(domain, entry)).join('\n')}
      </urlset>
    `;
  }

  function process(sitemapWithLocals, helperFns, db) {
    const next = {};
    const domain = config.domain;

    next.writePath = 'sitemap';
    next.contentsToWrite = createSitemap(domain, db.get('templateVariables').sitemap);
    return next;
  }

  function postprocess(sitemap) {
    if (config.productionMode) {
      sitemap.contentsToWrite = sitemap.contentsToWrite
          .replace(/<.*><\/.*>/g, '') // remove empty tags (must be first!)
          .replace(/\n/g, '') // remove newline
          .replace(/\s\s+/g, ''); // remove empty space
      return sitemap;
    }
    sitemap.contentsToWrite = sitemap.contentsToWrite.replace(/<.*><\/.*>/g, '');
    return sitemap;
  }
{'fraction_non_alphanumeric': 0.16365178066704353, 'fraction_numerical': 0.002826455624646693, 'mean_word_length': 3.1684334511189634, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 2, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '104427', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1099, 'n_words': 204}