<commit_before>import React from 'react';
import { Route } from 'react-router';
import config from 'config'; // Aliased through webpack
import _ from 'lodash';
import PropTypes from 'prop-types';
import paths from './paths';

const BodyContent = ({ location }) => {
  const allPages = paths.getAllPages(config);
  const page = paths.getPageForPath(config, location.pathname, allPages);
  const section = getSection(page, location.pathname, allPages);

  return renderSection(
    page,
    { config, section, page, location },
    section
  );
};
BodyContent.propTypes = {
  location: PropTypes.object
};

function getSection(page, pathname, allPages) {
  const sectionName = page.sectionName;
  const section = config.paths[sectionName || '/'] || config.paths['/'] || {};

  section.name = sectionName;

  // Get all pages of all sections
  section.all = () => getAllSectionPages(allPages);

  // Get pages of the current section or the named one
  section.pages = name => getSectionPages(config, name || sectionName, allPages);

  return section;
}

function getAllSectionPages(allPages) {
  return _.map(config.paths, (({ title }, name) => ({
    url: name,
    title,
    pages: getSectionPages(name, allPages)
  })));
}

function getSectionPages(config, name, allPages) {
  return _.filter(
    paths.getSectionPages(config, name, allPages),
    p => p.type === 'page'
  );
}

function renderSection(page, props, section) {
  let content;

  // TODO: It would be nice to handle redirects here during development
  if (page.type === 'page') {
    // Ok, got a page now. render it using a page template
    content = React.createFactory(page.layout)(
      props,
      React.createFactory(page, props)
    );
  } else if (page.type === 'index' || page.type === 'custom') {
    content = React.createFactory(page.layout)(props);
  } else {
    console.warn('Trying to render a page with an unknown type', page.type, page, props, section);
  }

  if (config.layout) {
    return React.createFactory(config.layout())(
      {},
      content
    );
  }

  return content;
}

export default () => (
  <Route exact strict component={BodyContent} />
);<commit_msg>fix: Fail hard if trying to render a page with an unknown type<commit_after>import React from 'react';
import { Route } from 'react-router';
import config from 'config'; // Aliased through webpack
import _ from 'lodash';
import PropTypes from 'prop-types';
import paths from './paths';

const BodyContent = ({ location }) => {
  const allPages = paths.getAllPages(config);
  const page = paths.getPageForPath(config, location.pathname, allPages);
  const section = getSection(page, location.pathname, allPages);

  return renderSection(
    page,
    { config, section, page, location },
    section
  );
};
BodyContent.propTypes = {
  location: PropTypes.object
};

function getSection(page, pathname, allPages) {
  const sectionName = page.sectionName;
  const section = config.paths[sectionName || '/'] || config.paths['/'] || {};

  section.name = sectionName;

  // Get all pages of all sections
  section.all = () => getAllSectionPages(allPages);

  // Get pages of the current section or the named one
  section.pages = name => getSectionPages(config, name || sectionName, allPages);

  return section;
}

function getAllSectionPages(allPages) {
  return _.map(config.paths, (({ title }, name) => ({
    url: name,
    title,
    pages: getSectionPages(name, allPages)
  })));
}

function getSectionPages(config, name, allPages) {
  return _.filter(
    paths.getSectionPages(config, name, allPages),
    p => p.type === 'page'
  );
}

function renderSection(page, props, section) {
  let content;

  // TODO: It would be nice to handle redirects here during development
  if (page.type === 'page') {
    // Ok, got a page now. render it using a page template
    content = React.createFactory(page.layout)(
      props,
      React.createFactory(page, props)
    );
  } else if (page.type === 'index' || page.type === 'custom') {
    content = React.createFactory(page.layout)(props);
  } else {
    console.error('Trying to render a page with an unknown type', page.type, page, props, section);
  }

  if (config.layout) {
    return React.createFactory(config.layout())(
      {},
      content
    );
  }

  return content;
}

export default () => (
  <Route exact strict component={BodyContent} />
);
{'fraction_non_alphanumeric': 0.13557384545038867, 'fraction_numerical': 0.0, 'mean_word_length': 3.6592119275825348, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '2751486', 'n_tokens_mistral': 1304, 'n_tokens_neox': 1292, 'n_words': 386}