class Jekyll::Algolia::Site

def push

Public: Extract records from every file and index them
def push
  records = []
  files = []
  progress_bar = ProgressBar.create(
    total: indexable_item_count,
    format: 'Extracting records (%j%%) |%B|'
  )
  each_site_file do |file|
    # Even if we cleared the list of documents/pages beforehand, some
    # files might still sneak up to this point (like static files added to
    # a collection directory), so we check again if they can really be
    # indexed.
    next unless FileBrowser.indexable?(file)
    path = FileBrowser.relative_path(file.path)
    Logger.verbose("I:Extracting records from #{path}")
    file_records = Extractor.run(file)
    files << file
    records += file_records
    progress_bar.increment
  end
  # Applying the user hook on the whole list of records
  records = Hooks.apply_all(records, self)
  # Shrinking records to force them to fit under the max record size
  # limit, or displaying an error message if not possible
  max_record_size = Configurator.algolia('max_record_size')
  # We take into account the objectID that will be added in the form of:
  # "objectID": "16cd998991cc40d92402b0b4e6c55e8a"
  object_id_attribute_length = 46
  max_record_size -= object_id_attribute_length
  records.map! do |record|
    Shrinker.fit_to_size(record, max_record_size)
  end
  # Adding a unique objectID to each record
  records.map! do |record|
    Extractor.add_unique_object_id(record)
  end
  Logger.verbose("I:Found #{files.length} files")
  Indexer.run(records)
end