Method: Lookbook::PageCollection#load

Defined in:
lib/lookbook/entities/collections/page_collection.rb

#load(page_paths) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/lookbook/entities/collections/page_collection.rb', line 5

def load(page_paths)
  @entities = []
  clear_cache

  file_paths = page_paths.flat_map do |dir|
    PathUtils.normalize_paths(Dir["#{dir}/**/*.html.*", "#{dir}/**/*.md.*"].sort)
  end

  entities = file_paths.map { |path| PageCollection.entity(path) }
  pages, sections = entities.partition { |page| page.type == :page }

  page_dict = pages.index_by(&:lookup_path)
  sections.each do |section|
    parent = page_dict[section.lookup_path]
    section.parent = parent
    parent.add_section(section)
  end

  add(pages)
end