<commit_before>const path = require('path')
const { h } = require('preact')
const render = require('preact-render-to-string')
const decache = require('decache')

const defaultOptions = {
  cache: true,
  doctype: '<!DOCTYPE html>',
}

function clearRequireCache(entries) {
  for (let i = 0; i < entries.length; i += 1) {
    decache(entries[i])
  }
}

exports.compile = (template, compileOptions) => (context) => {
  const options = Object.assign(defaultOptions, compileOptions)

  const ViewElement = require(options.filename)
  const Element = ViewElement.default || ViewElement

  if (typeof options.beforeRender === 'function') {
    options.beforeRender()
  }

  if (options.layout) {
    const layoutPath = path.join(options.layoutPath, options.layout)
    const LayoutElement = require(layoutPath)
    // eslint-disable-next-line no-unused-vars
    const Layout = LayoutElement.default || LayoutElement

    if (!options.cache) {
      clearRequireCache([options.filename, layoutPath])
    }

    return `${options.doctype}${render(
      <Layout>
        <Element {...context} />
      </Layout>,
    )}`
  }

  if (!options.cache) {
    clearRequireCache([options.filename])
  }
<commit_msg>Consistend usage (#8)<commit_after>const path = require('path')
const { h } = require('preact')
const render = require('preact-render-to-string')
const decache = require('decache')

const defaultOptions = {
  cache: true,
  doctype: '<!DOCTYPE html>',
}

function clearRequireCache(entries) {
  for (let i = 0; i < entries.length; i += 1) {
    decache(entries[i])
  }
}

exports.compile = (template, compileOptions) => (context) => {
  const options = Object.assign(defaultOptions, compileOptions)

  const ViewElement = require(options.filename)
  const Element = ViewElement.default || ViewElement

  if (typeof options.beforeRender === 'function') {
    options.beforeRender()
  }

  if (options.layout) {
    const layoutPath = path.join(options.layoutPath, options.layout)
    const LayoutElement = require(layoutPath)
    const Layout = LayoutElement.default || LayoutElement

    if (!options.cache) {
      clearRequireCache([options.filename, layoutPath])
    }

    return `${options.doctype}${render(
      Layout({ children: Element(context) }),
    )}`
  }

  if (!options.cache) {
    clearRequireCache([options.filename])
  }

{'fraction_non_alphanumeric': 0.14175918018787362, 'fraction_numerical': 0.002134927412467976, 'mean_word_length': 3.8914405010438413, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 12, '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': '1816419', 'n_tokens_mistral': 716, 'n_tokens_neox': 695, 'n_words': 155}