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

var fs = require('fs-extra');

var Markdown = require('markdown-it');
var jade = require('jade');

var sass = require('node-sass');
var uncss = require('uncss');
var CleanCSS = require('clean-css');

var stringRequire = function (module, filename) {
  module.exports = fs.readFileSync(filename, 'utf8');
};

require.extensions['.md'] = stringRequire;

// CSS
var css = sass.renderSync({
  file: './docs/sass/style.scss'
}).css.toString();

var md = new Markdown({ html: true });
md.use(require('markdown-it-anchor'));
md.use(require('markdown-it-table-of-contents'), { includeLevel: [2,3] });
if (process.env.NODE_ENV === 'production')
  md.use(require('markdown-it-imgix'), {
    match: "images",
    domain: 'io808.imgix.net',
    params: {
      ch: 'DPR',
      dpr: 2,
      h: 300,
      auto: 'compress'
    }
  });

// pages
var tutorialMD = require('./docs/tutorial.md');
var content = md.render(tutorialMD);

// render
var fn = jade.compileFile('./docs/template.jade', {});

// remove unused css
var testHtml = fn({ content: content, css: ""});

uncss(testHtml, {
  ignore: ['canvas'],
  raw: css
}, function(err, unCSS) {
  if (err) return console.error(err);

  var outputCSS = new CleanCSS({ roundingPrecision: -1 }).minify(unCSS).styles;

  var html = fn({ content: content, css: outputCSS });

  var htmlPath = './out/tutorial.html';
  var imagesPath = './out/images';

  fs.outputFileSync(htmlPath, html);
  fs.copySync('./docs/images', imagesPath, { clobber: true });
});<commit_msg>update buildDocs function to only minify css when being built for production<commit_after>#!/usr/bin/env node

var fs = require('fs-extra');

var Markdown = require('markdown-it');
var jade = require('jade');

var sass = require('node-sass');
var uncss = require('uncss');
var CleanCSS = require('clean-css');

var stringRequire = function (module, filename) {
  module.exports = fs.readFileSync(filename, 'utf8');
};

require.extensions['.md'] = stringRequire;

function renderHtml(content, css) {
  var html = fn({ content: content, css: css });

  var htmlPath = './out/tutorial.html';
  var imagesPath = './out/images';

  fs.outputFileSync(htmlPath, html);
  fs.copySync('./docs/images', imagesPath, { clobber: true });
}

// CSS
var rawCSS = sass.renderSync({
  file: './docs/sass/style.scss'
}).css.toString();

var md = new Markdown({ html: true });
md.use(require('markdown-it-anchor'));
md.use(require('markdown-it-table-of-contents'), { includeLevel: [2,3] });
if (process.env.NODE_ENV === 'production')
  md.use(require('markdown-it-imgix'), {
    match: "images",
    domain: 'io808.imgix.net',
    params: {
      ch: 'DPR',
      dpr: 2,
      h: 300,
      auto: 'compress'
    }
  });

// pages
var tutorialMD = require('./docs/tutorial.md');
var content = md.render(tutorialMD);

// render
var fn = jade.compileFile('./docs/template.jade', {});

// remove unused css
var testHtml = fn({ content: content, css: ""});

if (process.env.NODE_ENV === 'production') {
  uncss(testHtml, {
    ignore: ['canvas'],
    raw: rawCSS
  }, function(err, unCSS) {
    if (err) return console.error(err);

    var prodCSS = new CleanCSS({ roundingPrecision: -1 }).minify(unCSS).styles;

    renderHtml(content, prodCSS);
  });
} else {
  renderHtml(content, rawCSS);
}
{'fraction_non_alphanumeric': 0.18990021167221047, 'fraction_numerical': 0.006652555185969156, 'mean_word_length': 3.9007407407407406, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '560740', 'n_tokens_mistral': 1165, 'n_tokens_neox': 1124, 'n_words': 264}