<commit_before>React = require 'react'
Router = require 'react-router'
find = require 'lodash/collection/find'
filter = require 'lodash/collection/filter'
createRoutes = require 'create-routes'
app = require 'app'

# TODO add extra file watcher here to reload config when file add/removed
# TODO check if this is called when a new file is added. Narrow down problems
loadConfig = (cb) ->
  stuff = require 'config'
  if module.hot
    module.hot.accept stuff.id, ->
      cb()

  cb()

loadConfig ->
  app.loadContext (pagesReq) ->
    {pages, config, relativePath} = require 'config'

    routes = createRoutes(pages, pagesReq)

    # Remove templates files.
    pages = filter(pages, (page) -> page.path?)

    if router
      router.replaceRoutes [app]
    else
      router = Router.run [routes], Router.HistoryLocation, (Handler, state) ->
        page = find pages, (page) -> page.path is state.pathname
        React.render(
          <Handler<commit_msg>Add hook so sites can respond to route changes<commit_after>React = require 'react'
Router = require 'react-router'
find = require 'lodash/collection/find'
filter = require 'lodash/collection/filter'
createRoutes = require 'create-routes'
app = require 'app'

# TODO add extra file watcher here to reload config when file add/removed
# TODO check if this is called when a new file is added. Narrow down problems
loadConfig = (cb) ->
  stuff = require 'config'
  if module.hot
    module.hot.accept stuff.id, ->
      cb()

  cb()

loadConfig ->
  app.loadContext (pagesReq) ->
    {pages, config, relativePath} = require 'config'

    routes = createRoutes(pages, pagesReq)

    # Remove templates files.
    pages = filter(pages, (page) -> page.path?)

    # Route already exists meaning we're hot-reloading.
    if router
      router.replaceRoutes [app]
    else
      router = Router.run [routes], Router.HistoryLocation, (Handler, state) ->
        page = find pages, (page) -> page.path is state.pathname

        # Let app know the route is changing.
        if app.onRouteChange then app.onRouteChange(state, page, pages, config)

        React.render(
          <Handler
{'fraction_non_alphanumeric': 0.10509107893507706, 'fraction_numerical': 0.0, 'mean_word_length': 3.135135135135135, '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': '5290954', 'n_tokens_mistral': 634, 'n_tokens_neox': 628, 'n_words': 215}