Class: Jekyll::Drops::SiteDrop

Inherits:
Drop
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/jekyll/drops/site_drop.rb

Constant Summary

Constants inherited from Drop

Drop::NON_CONTENT_METHODS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Drop

#[]=, #content_methods, #each, #each_key, #fetch, #hash_for_json, #initialize, #inspect, #keys, #merge, #merge!, mutable, mutable?, #to_h, #to_json

Constructor Details

This class inherits a constructor from Jekyll::Drops::Drop

Instance Attribute Details

#current_document=(value) ⇒ Object (writeonly)

Sets the attribute current_document

Parameters:

  • value

    the value to set the attribute current_document to.


60
61
62
# File 'lib/jekyll/drops/site_drop.rb', line 60

def current_document=(value)
  @current_document = value
end

Instance Method Details

#[](key) ⇒ Object


15
16
17
18
19
20
21
# File 'lib/jekyll/drops/site_drop.rb', line 15

def [](key)
  if key != "posts" && @obj.collections.key?(key)
    @obj.collections[key].docs
  else
    super(key)
  end
end

#collectionsObject


37
38
39
# File 'lib/jekyll/drops/site_drop.rb', line 37

def collections
  @site_collections ||= @obj.collections.values.sort_by(&:label).map(&:to_liquid)
end

#configObject

return nil for `site.config }` even if –config was passed via CLI


63
# File 'lib/jekyll/drops/site_drop.rb', line 63

def config; end

#documentsObject

`Site#documents` cannot be memoized so that `Site#docs_to_write` can access the latest state of the attribute.

Since this method will be called after `Site#pre_render` hook, the `Site#documents` array shouldn't thereafter change and can therefore be safely memoized to prevent additional computation of `Site#documents`.


47
48
49
# File 'lib/jekyll/drops/site_drop.rb', line 47

def documents
  @documents ||= @obj.documents
end

#html_pagesObject


31
32
33
34
35
# File 'lib/jekyll/drops/site_drop.rb', line 31

def html_pages
  @site_html_pages ||= @obj.pages.select do |page|
    page.html? || page.url.end_with?("/")
  end
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)

23
24
25
# File 'lib/jekyll/drops/site_drop.rb', line 23

def key?(key)
  (key != "posts" && @obj.collections.key?(key)) || super
end

#postsObject


27
28
29
# File 'lib/jekyll/drops/site_drop.rb', line 27

def posts
  @site_posts ||= @obj.posts.docs.sort { |a, b| b <=> a }
end

`site.related_posts }` is how posts can get posts related to them, either through LSI if it's enabled, or through the most recent posts. We should remove this in 4.0 and switch to `post.related_posts }`.


55
56
57
58
59
# File 'lib/jekyll/drops/site_drop.rb', line 55

def related_posts
  return nil unless @current_document.is_a?(Jekyll::Document)

  @current_document.related_posts
end