class Jekyll::Reader

def conditionally_generate_entry(entry_path, container, reader)

def conditionally_generate_entry(entry_path, container, reader)
  return if container.find { |item| site.in_source_dir(item.relative_path) == entry_path }
  dir, files = File.split(entry_path)
  dir.sub!(site.source, "")
  files = Array(files)
  container.concat(reader.new(site, dir).read(files))
end

def filter_entries(entries, base_directory = nil)

Returns the Array of filtered entries.

base_directory - The string representing the optional base directory.
entries - The Array of String file/directory entries to filter.

files such as '.htaccess'.
or are excluded in the site configuration, unless they are web server
with "." or "#" or end with "~"), or contain site content (start with "_"),
Filter out any files/directories that are hidden or backup files (start
def filter_entries(entries, base_directory = nil)
  EntryFilter.new(site, base_directory).filter(entries)
end

def get_entries(dir, subfolder)

Returns the list of entries to process

subfolder - The String representing the directory to read.
dir - The String representing the relative path of the directory to read.

Read the entries from a particular directory for processing
def get_entries(dir, subfolder)
  base = site.in_source_dir(dir, subfolder)
  return [] unless File.exist?(base)
  entries = Dir.chdir(base) { filter_entries(Dir["**/*"], base) }
  entries.delete_if { |e| File.directory?(site.in_source_dir(base, e)) }
end

def initialize(site)

def initialize(site)
  @site = site
end

def outside_configured_directory?(dir)

outside that directory.
Returns true if a custom collections_dir has been set but current directory lies

posts and drafts only from within that directory.
If the user has defined a custom collections_dir, then attempt to read
Determine if the directory is supposed to contain posts and drafts.

Internal
def outside_configured_directory?(dir)
  collections_dir = site.config["collections_dir"]
  !collections_dir.empty? && !dir.start_with?("/#{collections_dir}")
end

def post_reader

directories in current site.
Create a single PostReader instance to retrieve drafts and posts from all valid
def post_reader
  @post_reader ||= PostReader.new(site)
end

def read

Returns nothing.

Read Site data from disk and load it into internal data structures.
def read
  @site.layouts = LayoutReader.new(site).read
  read_directories
  read_included_excludes
  sort_files!
  CollectionReader.new(site).read
  ThemeAssetsReader.new(site).read
  read_data
end

def read_data

Returns nothing.

semantics of Utils.deep_merge_hashes.
Site data will overwrite theme data with the same key using the
If a theme is specified and it contains data, it will be read.
Read and merge the data files.
def read_data
  @site.data = DataReader.new(site).read(site.config["data_dir"])
  return unless site.theme&.data_path
  theme_data = DataReader.new(
    site,
    :in_source_dir => site.method(:in_theme_dir)
  ).read(site.theme.data_path)
  @site.data = Jekyll::Utils.deep_merge_hashes(theme_data, @site.data)
end

def read_directories(dir = "")

Returns nothing.

dir - The String relative path of the directory to read. Default: ''.

filter_entries.
that will become part of the site according to the rules in
Recursively traverse directories to find pages and static files
def read_directories(dir = "")
  base = site.in_source_dir(dir)
  return unless File.directory?(base)
  dot_dirs = []
  dot_pages = []
  dot_static_files = []
  dot = Dir.chdir(base) { filter_entries(Dir.entries("."), base) }
  dot.each do |entry|
    file_path = @site.in_source_dir(base, entry)
    if File.directory?(file_path)
      dot_dirs << entry
    elsif Utils.has_yaml_header?(file_path)
      dot_pages << entry
    else
      dot_static_files << entry
    end
  end
  retrieve_posts(dir)
  retrieve_dirs(base, dir, dot_dirs)
  retrieve_pages(dir, dot_pages)
  retrieve_static_files(dir, dot_static_files)
end

def read_included_excludes

def read_included_excludes
  entry_filter = EntryFilter.new(site)
  site.include.each do |entry|
    entry_path = site.in_source_dir(entry)
    next if File.directory?(entry_path)
    next if entry_filter.symlink?(entry_path)
    read_included_file(entry_path) if File.file?(entry_path)
  end
end

def read_included_file(entry_path)

def read_included_file(entry_path)
  if Utils.has_yaml_header?(entry_path)
    conditionally_generate_entry(entry_path, site.pages, PageReader)
  else
    conditionally_generate_entry(entry_path, site.static_files, StaticFileReader)
  end
end

def retrieve_dirs(_base, dir, dot_dirs)

Returns nothing.

dot_dirs - The Array of subdirectories in the dir.
dir - The String representing the directory to traverse down.
base - The String representing the site's base directory.

Recursively traverse directories with the read_directories function.
def retrieve_dirs(_base, dir, dot_dirs)
  dot_dirs.each do |file|
    dir_path = site.in_source_dir(dir, file)
    rel_path = PathManager.join(dir, file)
    @site.reader.read_directories(rel_path) unless @site.dest.chomp("/") == dir_path
  end
end

def retrieve_pages(dir, dot_pages)

Returns nothing.

dot_pages - The Array of pages in the dir.
dir - The String representing the directory retrieve the pages from.

add them to the site and sort them.
Retrieve all the pages from the current directory,
def retrieve_pages(dir, dot_pages)
  site.pages.concat(PageReader.new(site, dir).read(dot_pages))
end

def retrieve_posts(dir)

Returns nothing.

dir - The String representing the directory to retrieve the posts from.

and add them to the site and sort them.
Retrieves all the posts(posts/drafts) from the given directory
def retrieve_posts(dir)
  return if outside_configured_directory?(dir)
  site.posts.docs.concat(post_reader.read_posts(dir))
  site.posts.docs.concat(post_reader.read_drafts(dir)) if site.show_drafts
end

def retrieve_static_files(dir, dot_static_files)

Returns nothing.

dot_static_files - The static files in the dir.
dir - The directory retrieve the static files from.

add them to the site and sort them.
Retrieve all the static files from the current directory,
def retrieve_static_files(dir, dot_static_files)
  site.static_files.concat(StaticFileReader.new(site, dir).read(dot_static_files))
end

def sort_files!

Sorts posts, pages, and static files.
def sort_files!
  site.collections.each_value { |c| c.docs.sort! }
  site.pages.sort_by!(&:name)
  site.static_files.sort_by!(&:relative_path)
end