class Jekyll::Excerpt

Attributes

content[RW]
doc[RW]
ext[RW]
output[W]

Public Class Methods

new(doc) click to toggle source

Initialize this Excerpt instance.

doc - The Document.

Returns the new Excerpt.

# File lib/jekyll/excerpt.rb, line 17
def initialize(doc)
  self.doc = doc
  self.content = extract_excerpt(doc.content)
end

Public Instance Methods

data() click to toggle source

Fetch YAML front-matter data from related doc, without layout key

Returns Hash of doc data

# File lib/jekyll/excerpt.rb, line 25
def data
  @data ||= doc.data.dup
  @data.delete("layout")
  @data.delete("excerpt")
  @data
end
id() click to toggle source

The UID for this doc (useful in feeds). e.g. /2008/11/05/my-awesome-doc

Returns the String UID.

# File lib/jekyll/excerpt.rb, line 53
def id
  "#{doc.id}#excerpt"
end
include?(something) click to toggle source

Check if excerpt includes a string

Returns true if the string passed in

# File lib/jekyll/excerpt.rb, line 45
def include?(something)
  (output && output.include?(something)) || content.include?(something)
end
inspect() click to toggle source

Returns the shorthand String identifier of this doc.

# File lib/jekyll/excerpt.rb, line 69
def inspect
  "<Excerpt: #{self.id}>"
end
output() click to toggle source
# File lib/jekyll/excerpt.rb, line 73
def output
  @output ||= Renderer.new(doc.site, self, site.site_payload).run
end
path() click to toggle source

'Path' of the excerpt.

Returns the path for the doc this excerpt belongs to with excerpt appended

# File lib/jekyll/excerpt.rb, line 38
def path
  File.join(doc.path, "#excerpt")
end
place_in_layout?() click to toggle source
# File lib/jekyll/excerpt.rb, line 77
def place_in_layout?
  false
end
to_liquid() click to toggle source
# File lib/jekyll/excerpt.rb, line 61
def to_liquid
  doc.data['excerpt'] = nil
  @to_liquid ||= doc.to_liquid
  doc.data['excerpt'] = self
  @to_liquid
end
to_s() click to toggle source
# File lib/jekyll/excerpt.rb, line 57
def to_s
  output || content
end
trigger_hooks(*) click to toggle source
# File lib/jekyll/excerpt.rb, line 32
def trigger_hooks(*)
end

Protected Instance Methods

extract_excerpt(doc_content) click to toggle source

Internal: Extract excerpt from the content

By default excerpt is your first paragraph of a doc: everything before the first two new lines:

---
title: Example
---

First paragraph with [link][1].

Second paragraph.

[1]: http://example.com/

This is fairly good option for Markdown and Textile files. But might cause problems for HTML docs (which is quite unusual for Jekyll). If default excerpt delimiter is not good for you, you might want to set your own via configuration option `excerpt_separator`. For example, following is a good alternative for HTML docs:

# file: _config.yml
excerpt_separator: "<!-- more -->"

Notice that all markdown-style link references will be appended to the excerpt. So the example doc above will have this excerpt source:

First paragraph with [link][1].

[1]: http://example.com/

Excerpts are rendered same time as content is rendered.

Returns excerpt String

# File lib/jekyll/excerpt.rb, line 117
def extract_excerpt(doc_content)
  head, _, tail = doc_content.to_s.partition(doc.excerpt_separator)

  if tail.empty?
    head
  else
    "" << head << "\n\n" << tail.scan(/^\[[^\]]+\]:.+$/).join("\n")
  end
end