<commit_before>const gulp = require('gulp')
const fs = require('fs')
const request = require('request')
const jimp = require('jimp')
const { groupBy, forIn } = require('lodash')

const configPath = process.cwd() + '/data/config.json'
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'))
const methode = config.copy.methode
const imageSizes = [ 640, 1280, 1920 ]
const imageDirectory = 'assets/methode/'
let imagesToDownload = []
let firstAdSlotted = false

const getImageDirectory = () => {
	const dir = methode.imageDirectory || ''
	const finalDir = dir ? `${dir}/` : dir

}

const createPicturefill = ({ name, extension, caption }) => {
	const srcset = methode.imageLibrary === 'picturefill' ? 'srcset' : 'data-srcset'
	const lazyload = methode.imageLibrary === 'picturefill' ? '' : 'lazyload'
	const defaultSrc = `<% if(projectType === 'Multipage') { %>/${config.path}/<% } %>${imageDirectory}${name}placeholder.${extension}`

	const getPath = (sz) => `<% if(projectType === 'Multipage') { %>/${config.path}/<% } %>${imageDirectory}${name}${sz}.${extension}`
	const getSource = (src, mq) => `<source ${srcset}='${src}' media='(min-width:${mq}px)'>`
	const reversed = imageSizes.map(i => i).reverse()

	return `
		<picture>
			<!--[if IE 9]><video style='display: none;'><![endif]-->
			${
				reversed.map((sz, index) => {
					const src = getPath(sz)
					const mq = index < reversed.length - 1
						? Math.floor(reversed[index + 1] / 1.5)
						: 1
					return getSource(src, mq)
				}).join('')
			}
			<!--[if IE 9]></video><![endif]-->
			<img class='${lazyload}' src='${defaultSrc}' ${srcset}='${defaultSrc}' alt='${caption}' />
		</picture>
	`.trim()
}

const createFigureSource = ({ name, extension, caption }) => {

	if (methode.imageLibrary) {
		return createPicturefill({ name, extension, caption })
	}
	// plain old image default
	const src = `<% if(projectType === 'Multipage') { %>/${config.path}/<% } %>${imageDirectory}${name}${imageSizes[imageSizes.length - 1]}.${extension}`
	return `<img src='${src}' alt='${caption}' />`
}

const getImageInfo = (imagePath) => {
	const imageFull = imagePath.substr(imagePath.lastIndexOf('/') + 1)
	const imageSplit = imageFull.split('.')
	const name = `${imageSplit[0]}_apps_w_`
	const extension = imageSplit[1]
	return { name, extension }
}

const replaceMethodeImageSize = ({ imagePath, imageSize }) =>
	imagePath.replace(/image_(.+\d)w/g, `image_${imageSize}w`)

const replaceLocalImageSize = ({ imagePath, imageSize }) =>
	imagePath.replace(/_apps_w_(.+\d)\./g, `_apps_w_${imageSize}.`)

const createFigure = ({ href, credit, caption, alt }) => {
	const imagePath = href.split('?')[0]
	const { name, extension } = getImageInfo(imagePath)

	// start generating markup
	const src = createFigureSource({ name, extension, caption })

	// add to download queue
	const imageSize = 1920
	const url = `http:${replaceMethodeImageSize({ imagePath, imageSize })}`
	const filename = `${name}${imageSize}.${extension}`

	imagesToDownload.push({ url, filename })

	return `
		<figure>
			${src}
			<small class='figure-credit'>${credit}</small>
			<figcaption class='figure-caption'>${caption}</figcaption>
		</figure>
	`.trim()
}

const cleanP = (content) => {
	// check for graphic partial first
	if (content.match(/{{graphic:(.*)}}/)) {
		return content.replace(/{{graphic:(.*)}}/, (match, name, index) =>
			`{{> graphic/${name.trim()} }}`
		)
	}

	const stripped = content
		.replace(/<span(.*?)>/g, '') // remove spans
		.replace(/<\/span>/g, '')<commit_msg>update figure bem in fetch-methode<commit_after>const gulp = require('gulp')
const fs = require('fs')
const request = require('request')
const jimp = require('jimp')
const { groupBy, forIn } = require('lodash')

const configPath = process.cwd() + '/data/config.json'
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'))
const methode = config.copy.methode
const imageSizes = [ 640, 1280, 1920 ]
const imageDirectory = 'assets/methode/'
let imagesToDownload = []
let firstAdSlotted = false

const getImageDirectory = () => {
	const dir = methode.imageDirectory || ''
	const finalDir = dir ? `${dir}/` : dir

}

const createPicturefill = ({ name, extension, caption }) => {
	const srcset = methode.imageLibrary === 'picturefill' ? 'srcset' : 'data-srcset'
	const lazyload = methode.imageLibrary === 'picturefill' ? '' : 'lazyload'
	const defaultSrc = `<% if(projectType === 'Multipage') { %>/${config.path}/<% } %>${imageDirectory}${name}placeholder.${extension}`

	const getPath = (sz) => `<% if(projectType === 'Multipage') { %>/${config.path}/<% } %>${imageDirectory}${name}${sz}.${extension}`
	const getSource = (src, mq) => `<source ${srcset}='${src}' media='(min-width:${mq}px)'>`
	const reversed = imageSizes.map(i => i).reverse()

	return `
		<picture class='figure__img'>
			<!--[if IE 9]><video style='display: none;'><![endif]-->
			${
				reversed.map((sz, index) => {
					const src = getPath(sz)
					const mq = index < reversed.length - 1
						? Math.floor(reversed[index + 1] / 1.5)
						: 1
					return getSource(src, mq)
				}).join('')
			}
			<!--[if IE 9]></video><![endif]-->
			<img class='${lazyload}' src='${defaultSrc}' ${srcset}='${defaultSrc}' alt='${caption}' />
		</picture>
	`.trim()
}

const createFigureSource = ({ name, extension, caption }) => {

	if (methode.imageLibrary) {
		return createPicturefill({ name, extension, caption })
	}
	// plain old image default
	const src = `<% if(projectType === 'Multipage') { %>/${config.path}/<% } %>${imageDirectory}${name}${imageSizes[imageSizes.length - 1]}.${extension}`
	return `<img src='${src}' alt='${caption}' />`
}

const getImageInfo = (imagePath) => {
	const imageFull = imagePath.substr(imagePath.lastIndexOf('/') + 1)
	const imageSplit = imageFull.split('.')
	const name = `${imageSplit[0]}_apps_w_`
	const extension = imageSplit[1]
	return { name, extension }
}

const replaceMethodeImageSize = ({ imagePath, imageSize }) =>
	imagePath.replace(/image_(.+\d)w/g, `image_${imageSize}w`)

const replaceLocalImageSize = ({ imagePath, imageSize }) =>
	imagePath.replace(/_apps_w_(.+\d)\./g, `_apps_w_${imageSize}.`)

const createFigure = ({ href, credit, caption, alt }) => {
	const imagePath = href.split('?')[0]
	const { name, extension } = getImageInfo(imagePath)

	// start generating markup
	const src = createFigureSource({ name, extension, caption })

	// add to download queue
	const imageSize = 1920
	const url = `http:${replaceMethodeImageSize({ imagePath, imageSize })}`
	const filename = `${name}${imageSize}.${extension}`

	imagesToDownload.push({ url, filename })

	return `
		<figure class='figure'>
			${src}
			<small class='figure__credit'>${credit}</small>
			<figcaption class='figure__caption'>${caption}</figcaption>
		</figure>
	`.trim()
}

const cleanP = (content) => {
	// check for graphic partial first
	if (content.match(/{{graphic:(.*)}}/)) {
		return content.replace(/{{graphic:(.*)}}/, (match, name, index) =>
			`{{> graphic/${name.trim()} }}`
		)
	}

	const stripped = content
		.replace(/<span(.*?)>/g, '') // remove spans
		.replace(/<\/span>/g, '')
{'fraction_non_alphanumeric': 0.2071830985915493, 'fraction_numerical': 0.007887323943661971, 'mean_word_length': 4.513198757763975, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7311789', 'n_tokens_mistral': 2577, 'n_tokens_neox': 2385, 'n_words': 516}