class Jekyll::Excerpt
Constants
- LIQUID_TAG_REGEX
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
- MKDWN_LINK_REF_REGEX
Attributes
Public Class Methods
Public Instance Methods
Fetch YAML front-matter data from related doc, without layout key
Returns Hash of doc data
# File lib/jekyll/excerpt.rb, line 31 def data @data ||= doc.data.dup @data.delete("layout") @data.delete("excerpt") @data end
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 65 def id "#{doc.id}#excerpt" end
Check if excerpt includes a string
Returns true if the string passed in
# File lib/jekyll/excerpt.rb, line 57 def include?(something) output&.include?(something) || content.include?(something) end
Returns the shorthand String identifier of this doc.
# File lib/jekyll/excerpt.rb, line 78 def inspect "<#{self.class} id=#{id}>" end
# File lib/jekyll/excerpt.rb, line 82 def output @output ||= Renderer.new(doc.site, self, site.site_payload).run end
‘Path’ of the excerpt.
Returns the path for the doc this excerpt belongs to with excerpt appended
# File lib/jekyll/excerpt.rb, line 43 def path File.join(doc.path, "#excerpt") end
# File lib/jekyll/excerpt.rb, line 86 def place_in_layout? false end
‘Relative Path’ of the excerpt.
Returns the relative_path
for the doc this excerpt belongs to with excerpt appended
# File lib/jekyll/excerpt.rb, line 50 def relative_path @relative_path ||= File.join(doc.relative_path, "#excerpt") end
# File lib/jekyll/excerpt.rb, line 90 def render_with_liquid? return false if data["render_with_liquid"] == false !(coffeescript_file? || yaml_file? || !Utils.has_liquid_construct?(content)) end
# File lib/jekyll/excerpt.rb, line 73 def to_liquid Jekyll::Drops::ExcerptDrop.new(self) end
# File lib/jekyll/excerpt.rb, line 69 def to_s output || content end
# File lib/jekyll/excerpt.rb, line 38 def trigger_hooks(*); end
Protected Instance Methods
# File lib/jekyll/excerpt.rb, line 136 def extract_excerpt(doc_content) head, _, tail = doc_content.to_s.partition(doc.excerpt_separator) return head if tail.empty? head = sanctify_liquid_tags(head) if head.include?("{%") definitions = extract_markdown_link_reference_definitions(head, tail) return head if definitions.empty? head << "\n\n" << definitions.join("\n") end
Private Instance Methods
# File lib/jekyll/excerpt.rb, line 175 def endtag_regex_stash(tag_name) @endtag_regex_stash ||= {} @endtag_regex_stash[tag_name] ||= %r!{%-?\s*end#{tag_name}.*?\s*-?%}!m end
# File lib/jekyll/excerpt.rb, line 167 def extract_markdown_link_reference_definitions(head, tail) [].tap do |definitions| tail.scan(MKDWN_LINK_REF_REGEX).each do |segments| definitions << segments.join if head.include?(segments[0]) end end end
# File lib/jekyll/excerpt.rb, line 180 def liquid_block?(tag_name) return false unless tag_name.is_a?(String) return false unless Liquid::Template.tags[tag_name] Liquid::Template.tags[tag_name].ancestors.include?(Liquid::Block) rescue NoMethodError Jekyll.logger.error "Error:", "A Liquid tag in the excerpt of #{doc.relative_path} couldn't be parsed." raise end
# File lib/jekyll/excerpt.rb, line 191 def print_build_warning Jekyll.logger.warn "Warning:", "Excerpt modified in #{doc.relative_path}!" Jekyll.logger.warn "", "Found a Liquid block containing the excerpt separator " \ "#{doc.excerpt_separator.inspect}." Jekyll.logger.warn "", "The block has been modified with the appropriate closing tag." Jekyll.logger.warn "", "Feel free to define a custom excerpt or excerpt_separator in the" Jekyll.logger.warn "", "document's Front Matter if the generated excerpt is unsatisfactory." end