<commit_before>const fs = require('fs');
const fsextra = require('fs-extra');
const path = require('path');
const util = require('util');
const logger = require('winston');

const sanitizeHtml = require('sanitize-html');

const blackfriday = require('./blackfriday.js');

const del = require('delete');
const exec = require('sync-exec');

const inputDirectoryGame = './citra-games-wiki';
const inputDirectoryWiki = './citra-games-wiki.wiki';
const outputDirectoryMd = '../../site/content/game';
const outputDirectoryBoxart = '../../site/static/images/game/boxart';
const outputDirectoryIcons = '../../site/static/images/game/icons';
const outputDirectoryScreenshots = '../../site/static/images/screenshots0';
const outputDirectorySavefiles = '../../site/static/savefiles/';

// The URL
function url(title) {
  return '/wiki/' + title.replace(/\s+/g, '-').toLowerCase();
}

function gitPull(directory, repository) {
  if (fs.existsSync(directory)) {
      logger.info(`Fetching latest from Github : ${directory}`);
      exec(`cd ${directory} && git pull && cd -`);
  } else {
      logger.info(`Cloning repository from Github : ${directory}`);
      exec(`git clone ${repository}`);
  }
}

function getDirectories (srcpath) {
  return fs.readdirSync(srcpath)
    .filter(file => fs.lstatSync(path.join(srcpath, file)).isDirectory())
}

String.prototype.trimNewline = function() {
  let string = this.toString();
  let match = '\r\n'
  if (string.endsWith('\r\n')) {
    return string.slice(0, -4);
  } else if (string.endsWith('\r') || string.endsWith('\n')) {
    return string.slice(0, -2);
  } else {
    return string;
  }
}

// Fetch game information stored in Github repository.
gitPull(inputDirectoryGame, 'https://github.com/citra-emu/citra-games-wiki.git');

// Fetch game articles stored in Github wiki.
gitPull(inputDirectoryWiki, 'https://github.com/citra-emu/citra-games-wiki.wiki.git');

// Make sure the output directories in Hugo exist.
if (fs.existsSync(outputDirectoryMd) == false) {
    logger.info(`Creating missing output directory: ${outputDirectoryMd}`);
    fs.mkdirSync(outputDirectoryMd);
}

if (fs.existsSync(outputDirectoryBoxart) == false) {
    logger.info(`Creating missing output directory: ${outputDirectoryBoxart}`);
    fs.mkdirSync(outputDirectoryBoxart);
}
<commit_msg>Corrected trimNewLine function to prevent build errors based on unescaped control character U+000D<commit_after>const fs = require('fs');
const fsextra = require('fs-extra');
const path = require('path');
const util = require('util');
const logger = require('winston');

const sanitizeHtml = require('sanitize-html');

const blackfriday = require('./blackfriday.js');

const del = require('delete');
const exec = require('sync-exec');

const inputDirectoryGame = './citra-games-wiki';
const inputDirectoryWiki = './citra-games-wiki.wiki';
const outputDirectoryMd = '../../site/content/game';
const outputDirectoryBoxart = '../../site/static/images/game/boxart';
const outputDirectoryIcons = '../../site/static/images/game/icons';
const outputDirectoryScreenshots = '../../site/static/images/screenshots0';
const outputDirectorySavefiles = '../../site/static/savefiles/';

// The URL
function url(title) {
  return '/wiki/' + title.replace(/\s+/g, '-').toLowerCase();
}

function gitPull(directory, repository) {
  if (fs.existsSync(directory)) {
      logger.info(`Fetching latest from Github : ${directory}`);
      exec(`cd ${directory} && git pull && cd -`);
  } else {
      logger.info(`Cloning repository from Github : ${directory}`);
      exec(`git clone ${repository}`);
  }
}

function getDirectories (srcpath) {
  return fs.readdirSync(srcpath)
    .filter(file => fs.lstatSync(path.join(srcpath, file)).isDirectory())
}

String.prototype.trimNewline = function() {
  let string = this.toString();
  if (string.endsWith('\r\n')) {
    return string.slice(0, -2);
  } else if (string.endsWith('\r') || string.endsWith('\n')) {
    return string.slice(0, -1);
  } else {
    return string;
  }
}

// Fetch game information stored in Github repository.
gitPull(inputDirectoryGame, 'https://github.com/citra-emu/citra-games-wiki.git');

// Fetch game articles stored in Github wiki.
gitPull(inputDirectoryWiki, 'https://github.com/citra-emu/citra-games-wiki.wiki.git');

// Make sure the output directories in Hugo exist.
if (fs.existsSync(outputDirectoryMd) == false) {
    logger.info(`Creating missing output directory: ${outputDirectoryMd}`);
    fs.mkdirSync(outputDirectoryMd);
}

if (fs.existsSync(outputDirectoryBoxart) == false) {
    logger.info(`Creating missing output directory: ${outputDirectoryBoxart}`);
    fs.mkdirSync(outputDirectoryBoxart);
}

{'fraction_non_alphanumeric': 0.16937553464499572, 'fraction_numerical': 0.002780153977758768, 'mean_word_length': 4.406936416184971, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 4, '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': '471201', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1450, 'n_words': 319}