Module: Jekyll::Draft
- Defined in:
- lib/draft.rb
Class Method Summary collapse
-
.draft?(doc) ⇒ Boolean
True by checking in this order: - document is in _drafts directory, detectable by doc==true - document front matter contains ‘published: false’.
-
.draft_html(doc) ⇒ Object
HTML that indicates if a doc is a draft or not.
-
.root(doc, site) ⇒ Object
Path to root of the collection that doc is a member of.
Class Method Details
.draft?(doc) ⇒ Boolean
Returns true by checking in this order:
-
document is in _drafts directory, detectable by doc==true
-
document front matter contains ‘published: false’.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/draft.rb', line 11 def draft?(doc) if doc.respond_to? :data return !doc.data['published'] if doc.data.key? 'published' return doc.data['draft'] if doc.data.key? 'draft' end if doc.respond_to? :[] return !doc['published'] if doc.key? 'published' return doc['draft'] if doc.key? 'draft' end return doc.draft if doc.respond_to? :draft false rescue StandardError => e @logger.error { e } false end |
.draft_html(doc) ⇒ Object
Returns HTML that indicates if a doc is a draft or not.
31 32 33 34 35 36 37 38 |
# File 'lib/draft.rb', line 31 def draft_html(doc) return '' unless draft? doc " <i class='jekyll_draft'>Draft</i>" rescue StandardError => e @logger.error { e. } '' end |
.root(doc, site) ⇒ Object
Returns path to root of the collection that doc is a member of.
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/draft.rb', line 41 def root(doc, site) return '/index.html' unless doc.respond_to?(:collection) collection_name = doc.collection docs = site.key?(collection_name) ? site[collection_name] : site.collections[collection_name].docs index = docs.find { |d| d.url.end_with? 'index.html' } return index.url if index docs.min.url end |