module Jekyll::Relations::Page

Public Instance Methods

ancestors() click to toggle source

A list of ancestors from the site index to the current page.

Returns an Array of Page objects or an empty Array.

# File lib/jekyll/relations/page.rb, line 22
def ancestors
  @ancestors ||= begin
    return [] unless parent
    ancestors = []
    i = self
    while i.parent
      ancestors << i.parent
      i = i.parent
    end
    ancestors.reverse
  end
end
Also aliased as: parents
children() click to toggle source

A list of the pages directly below this one in the folder structure.

Returns an Array of Page objects or an empty Array.

# File lib/jekyll/relations/page.rb, line 39
def children
  return [] unless html? && index?
  @children ||= begin
    depth = url.count('/')
    site.pages
      .select(&:html?)
      .select { |p| p.url.start_with?(url) && p.url.count('/') == depth + 1 }
  end
end
parent() click to toggle source

The next highest page in the folder structure.

Returns the Page object for the parent page.

# File lib/jekyll/relations/page.rb, line 9
def parent
  @parent ||= begin
    return nil unless html?
    depth = url.count('/')
    site.pages
      .select(&:html?)
      .find { |p| url.start_with?(p.url) && p.url.count('/') == depth - 1 }
  end
end
parents()
Alias for: ancestors
to_liquid(attrs = Jekyll::Page::ATTRIBUTES_FOR_LIQUID) click to toggle source

Convert the new Page data to a Hash suitable for use by Liquid.

Returns the Hash representation of this Page.

Calls superclass method
# File lib/jekyll/relations/page.rb, line 52
def to_liquid(attrs = Jekyll::Page::ATTRIBUTES_FOR_LIQUID)
  super(attrs + %w(parent ancestors parents children))
end