<commit_before>define (require) ->
  $ = require('jquery')
  Backbone = require('backbone')
  settings = require('cs!settings')
  require('backbone-associations')

  CONTENT_URI = "#{location.protocol}//#{settings.cnxarchive.host}:#{settings.cnxarchive.port}/contents"

  return class Node extends Backbone.AssociatedModel
    url: () -> "#{CONTENT_URI}/#{@id}"
    defaults:
      title: 'Untitled'
      authors: []

    parse: (response, options) ->
      if not response.content then return response
      # jQuery can not build a jQuery object with <head> or <body> tags,
      # and will instead move all elements in them up one level.
      # Use a regex to extract everything in the body and put it into a div instead.
      $body = $('<div>' + response.content.replace(/^[\s\S]*<body.*?>|<\/body>[\s\S]*$/g, '') + '</div>')
      $body.find('.title').eq(0).remove()
      response.content = $body.html()

      return response

    relations: [{
      type: Backbone.Many
      key: 'contents'
      relatedModel: Node
    }]

    findPage: (num) ->
      search = (item) ->
        contents = item.get('contents')
        for item in contents.models
          if item.get('page') is num
            return item
          else if item.get('contents')
            result = search(item)
            return result if result
        return

      return search(@)
<commit_msg>Don't overwrite titles from the ToC<commit_after>define (require) ->
  $ = require('jquery')
  Backbone = require('backbone')
  settings = require('cs!settings')
  require('backbone-associations')

  CONTENT_URI = "#{location.protocol}//#{settings.cnxarchive.host}:#{settings.cnxarchive.port}/contents"

  return class Node extends Backbone.AssociatedModel
    url: () -> "#{CONTENT_URI}/#{@id}"
    defaults:
      authors: []

    parse: (response, options) ->
      # Don't overwrite the title from the book's table of contents
      if @get('title')
        delete response.title

      if not response.content then return response
      # jQuery can not build a jQuery object with <head> or <body> tags,
      # and will instead move all elements in them up one level.
      # Use a regex to extract everything in the body and put it into a div instead.
      $body = $('<div>' + response.content.replace(/^[\s\S]*<body.*?>|<\/body>[\s\S]*$/g, '') + '</div>')
      $body.find('.title').eq(0).remove()
      response.content = $body.html()

      return response

    relations: [{
      type: Backbone.Many
      key: 'contents'
      relatedModel: Node
    }]

    findPage: (num) ->
      search = (item) ->
        contents = item.get('contents')
        for item in contents.models
          if item.get('page') is num
            return item
          else if item.get('contents')
            result = search(item)
            return result if result
        return

      return search(@)

{'fraction_non_alphanumeric': 0.14122137404580154, 'fraction_numerical': 0.0006939625260235947, 'mean_word_length': 2.5115712545676003, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 25, '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': '3504828', 'n_tokens_mistral': 844, 'n_tokens_neox': 823, 'n_words': 243}