<commit_before>#!/usr/bin/env node

'use strict';

const Metalsmith = require('metalsmith');
const autoprefixer = require('autoprefixer-stylus');
const collections = require('metalsmith-collections');
const feed = require('metalsmith-feed');
const layouts = require('metalsmith-layouts');
const markdown = require('metalsmith-markdown');
const prism = require('metalsmith-prism');
const stylus = require('metalsmith-stylus');
const permalinks = require('metalsmith-permalinks');
const path = require('path');
const fs = require('fs');
const ncp = require('ncp');

const filterStylusPartials = require('./plugins/filter-stylus-partials');
const mapHandlebarsPartials = require('./plugins/map-handlebars-partials');
const versions = require('./source/versions');

/** Build **/

// load template.json for given language, but use default language as fallback
// for properties which are not present in the given language
var Handlebars = require('handlebars');

const DEFAULT_LANG = 'en';
function i18nJSON (lang) {
  var defaultJSON = require(`./locale/${DEFAULT_LANG}/site.json`);
  var templateJSON = require(`./locale/${lang}/site.json`);
  var finalJSON = JSON.parse(JSON.stringify(defaultJSON));
  var merge = function (targetJSON, customJSON) {
    Object.keys(customJSON).forEach(function (key) {
      let value = customJSON[key];
      if (typeof value === 'object') {
        merge(targetJSON[key], value);
      } else {
        targetJSON[key] = value;
      }
    });
  };
  merge(finalJSON, templateJSON);
  return finalJSON;
}

function traverse (obj, str) {
  return str.split('.').reduce(function (o, x) { return o[x]; }, obj);
}

const source = {
  project: {
    versions,
    currentVersion: versions[0].version
  }
};

function buildlocale (locale) {
  console.time('[metalsmith] build/' + locale + ' finished');
    const siteJSON = path.join(__dirname, 'locale', locale, 'site.json');
    const metalsmith = Metalsmith(__dirname);
    metalsmith
    .metadata({
      site: require(siteJSON),
      project: source.project,
      i18n: i18nJSON(locale)
    })
    .source(path.join(__dirname, 'locale', locale))
    .use(collections({
      blog : {
        pattern: 'blog/**/*.md',
        sortBy: 'date',
        reverse: true,
        refer: false
      },
      lastWeekly: {
        pattern: 'blog/weekly-updates/*.md',
        sortBy: 'date',
        reverse: true,
        refer: false,
        limit: 1
      },
      tscMinutes: {
        pattern: 'foundation/tsc/minutes/*.md',
        sortBy: 'date',
        reverse: true,
        refer: false
      }
    }))
    .use(markdown({ langPrefix: 'language-' }))
    .use(prism())
    .use(filterStylusPartials())
    .use(stylus({
      compress: true,
      paths:[path.join(__dirname, 'layouts', 'css')],
      use: [autoprefixer()]
    }))
    .use(permalinks())
    .use(feed({
      collection: 'blog',
      destination: 'blog.xml',
      title: 'Node.js Blog'
    }))
    .use(feed({
      collection: 'tscMinutes',
      destination: 'tsc-minutes.xml',
      title: 'Node.js Technical Steering Committee meetings'
    }))
    .use(layouts({
      engine: 'handlebars',
      pattern: '**/*.html',
      partials: mapHandlebarsPartials(metalsmith, 'layouts', 'partials'),
      helpers: {
        equals: function (v1, v2, options) {
          return (v1 === v2) ? options.fn(this) : options.inverse(this);
        },
        i18n: function () {
          var env, key;

          // function(key, env)
          if (arguments.length === 2) {
            key = arguments[0];<commit_msg>Fix multiple copies of site.json in build<commit_after>#!/usr/bin/env node

'use strict';

const Metalsmith = require('metalsmith');
const autoprefixer = require('autoprefixer-stylus');
const collections = require('metalsmith-collections');
const feed = require('metalsmith-feed');
const layouts = require('metalsmith-layouts');
const markdown = require('metalsmith-markdown');
const prism = require('metalsmith-prism');
const stylus = require('metalsmith-stylus');
const permalinks = require('metalsmith-permalinks');
const path = require('path');
const fs = require('fs');
const ncp = require('ncp');

const filterStylusPartials = require('./plugins/filter-stylus-partials');
const mapHandlebarsPartials = require('./plugins/map-handlebars-partials');
const versions = require('./source/versions');

/** Build **/

// load template.json for given language, but use default language as fallback
// for properties which are not present in the given language
var Handlebars = require('handlebars');

const DEFAULT_LANG = 'en';
function i18nJSON (lang) {
  var defaultJSON = require(`./locale/${DEFAULT_LANG}/site.json`);
  var templateJSON = require(`./locale/${lang}/site.json`);
  var finalJSON = JSON.parse(JSON.stringify(defaultJSON));
  var merge = function (targetJSON, customJSON) {
    Object.keys(customJSON).forEach(function (key) {
      let value = customJSON[key];
      if (typeof value === 'object') {
        merge(targetJSON[key], value);
      } else {
        targetJSON[key] = value;
      }
    });
  };
  merge(finalJSON, templateJSON);
  return finalJSON;
}

function traverse (obj, str) {
  return str.split('.').reduce(function (o, x) { return o[x]; }, obj);
}

const source = {
  project: {
    versions,
    currentVersion: versions[0].version
  }
};

function buildlocale (locale) {
  console.time('[metalsmith] build/' + locale + ' finished');
    const siteJSON = path.join(__dirname, 'locale', locale, 'site.json');
    const metalsmith = Metalsmith(__dirname);
    metalsmith
    .metadata({
      site: require(siteJSON),
      project: source.project,
      i18n: i18nJSON(locale)
    })
    .source(path.join(__dirname, 'locale', locale))
    .use(collections({
      blog : {
        pattern: 'blog/**/*.md',
        sortBy: 'date',
        reverse: true,
        refer: false
      },
      lastWeekly: {
        pattern: 'blog/weekly-updates/*.md',
        sortBy: 'date',
        reverse: true,
        refer: false,
        limit: 1
      },
      tscMinutes: {
        pattern: 'foundation/tsc/minutes/*.md',
        sortBy: 'date',
        reverse: true,
        refer: false
      }
    }))
    .use(markdown({ langPrefix: 'language-' }))
    .use(prism())
    .use(filterStylusPartials())
    .use(stylus({
      compress: true,
      paths:[path.join(__dirname, 'layouts', 'css')],
      use: [autoprefixer()]
    }))
    .use(permalinks({
      relative: false
    }))
    .use(feed({
      collection: 'blog',
      destination: 'blog.xml',
      title: 'Node.js Blog'
    }))
    .use(feed({
      collection: 'tscMinutes',
      destination: 'tsc-minutes.xml',
      title: 'Node.js Technical Steering Committee meetings'
    }))
    .use(layouts({
      engine: 'handlebars',
      pattern: '**/*.html',
      partials: mapHandlebarsPartials(metalsmith, 'layouts', 'partials'),
      helpers: {
        equals: function (v1, v2, options) {
          return (v1 === v2) ? options.fn(this) : options.inverse(this);
        },
        i18n: function () {
          var env, key;

          // function(key, env)
          if (arguments.length === 2) {
            key = arguments[0];
{'fraction_non_alphanumeric': 0.15664491042910708, 'fraction_numerical': 0.004443827246215803, 'mean_word_length': 2.9768083931529543, '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': '2506179', 'n_tokens_mistral': 2290, 'n_tokens_neox': 2234, 'n_words': 509}