<commit_before>define (require) ->
  _ = require('underscore')
  Backbone = require('backbone')

  hashStripper = /[#].*$/
  routeStripper = /^[#\/]|\s+$/g
  trailingSlash = /\/$/

  return _.extend Backbone.history, {
    getFragment: (fragment, forcePushState) ->
      if not fragment
        fragment = @location.pathname + @location.search
        root = @root.replace(trailingSlash, '')
        if not fragment.indexOf(root) then fragment = fragment.slice(root.length)

      return fragment.replace(routeStripper, '')

    navigate: (fragment, options) ->
      if not Backbone.History.started then return false
      if not options or options is true then options = {trigger: !!options}

      url = @root + (fragment = @getFragment(fragment or ''))

      fragment = fragment.replace(hashStripper, '')

      if @fragment is fragment then return
      @fragment = fragment

      if fragment is '' and url isnt '/' then url = url.slice(0, -1)

      @history[if options.replace then 'replaceState' else 'pushState']({}, document.title, url)

      if options.trigger then return @loadUrl(fragment)
  }<commit_msg>removing extra content stack from history when navigating to a book<commit_after>define (require) ->
  _ = require('underscore')
  Backbone = require('backbone')

  hashStripper = /[#].*$/
  routeStripper = /^[#\/]|\s+$/g
  trailingSlash = /\/$/
  contents = /^contents\/([^:@/]+)@([^:/?]*):([1])\/([^]*)(\.*)$/

  return _.extend Backbone.history, {
    getFragment: (fragment, forcePushState) ->
      if not fragment
        fragment = @location.pathname + @location.search
        root = @root.replace(trailingSlash, '')
        if not fragment.indexOf(root) then fragment = fragment.slice(root.length)

      return fragment.replace(routeStripper, '')

    navigate: (fragment, options) ->
      if not Backbone.History.started then return false
      if not options or options is true then options = {trigger: !!options}

      url = @root + (fragment = @getFragment(fragment or ''))

      fragment = fragment.replace(hashStripper, '')

      if @fragment is fragment then return
      @fragment = fragment

      if fragment is '' and url isnt '/' then url = url.slice(0, -1)

      if options.replace or @fragment.match(contents)
        @history.replaceState({}, document.title, url)
      else
        @history.pushState({}, document.title, url)

      if options.trigger then return @loadUrl(fragment)
  }
{'fraction_non_alphanumeric': 0.14350143501435014, 'fraction_numerical': 0.002050020500205002, 'mean_word_length': 3.059900166389351, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '2969014', 'n_tokens_mistral': 731, 'n_tokens_neox': 706, 'n_words': 193}