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/ngage/jekyll/excerpt.rb, line 32 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/ngage/jekyll/excerpt.rb, line 66 def id "#{doc.id}#excerpt" end
Check if excerpt includes a string
Returns true if the string passed in
# File lib/ngage/jekyll/excerpt.rb, line 58 def include?(something) (output&.include?(something)) || content.include?(something) end
Returns the shorthand String identifier of this doc.
# File lib/ngage/jekyll/excerpt.rb, line 79 def inspect "<Excerpt: #{id}>" end
# File lib/ngage/jekyll/excerpt.rb, line 83 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/ngage/jekyll/excerpt.rb, line 44 def path File.join(doc.path, "#excerpt") end
# File lib/ngage/jekyll/excerpt.rb, line 87 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/ngage/jekyll/excerpt.rb, line 51 def relative_path @relative_path ||= File.join(doc.relative_path, "#excerpt") end
# File lib/ngage/jekyll/excerpt.rb, line 91 def render_with_liquid? return false if data["render_with_liquid"] == false !(coffeescript_file? || yaml_file? || !Utils.has_liquid_construct?(content)) end
# File lib/ngage/jekyll/excerpt.rb, line 74 def to_liquid Jekyll::Drops::ExcerptDrop.new(self) end
# File lib/ngage/jekyll/excerpt.rb, line 70 def to_s output || content end
# File lib/ngage/jekyll/excerpt.rb, line 39 def trigger_hooks(*); end
Protected Instance Methods
# File lib/ngage/jekyll/excerpt.rb, line 137 def extract_excerpt(doc_content) head, _, tail = doc_content.to_s.partition(doc.excerpt_separator) # append appropriate closing tag (to a Liquid block), to the "head" if the # partitioning resulted in leaving the closing tag somewhere in the "tail" # partition. if head.include?("{%") head =~ LIQUID_TAG_REGEX tag_name = Regexp.last_match(1) if liquid_block?(tag_name) && head.match(%r!{%-?\s*end#{tag_name}\s*-?%}!).nil? print_build_warning head << "\n{% end#{tag_name} %}" end end if tail.empty? head else head.to_s.dup << "\n\n" << tail.scan(MKDWN_LINK_REF_REGEX).join("\n") end end
Private Instance Methods
# File lib/ngage/jekyll/excerpt.rb, line 162 def liquid_block?(tag_name) Liquid::Template.tags[tag_name].superclass == 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/ngage/jekyll/excerpt.rb, line 170 def print_build_warning Jekyll.logger.warn "Warning:", "Excerpt modified in #{doc.relative_path}!" Jekyll.logger.warn "", "Found a Liquid block containing separator '#{doc.excerpt_separator}'" \ " and has been modified with the appropriate closing tag." Jekyll.logger.warn "", "Feel free to define a custom excerpt or excerpt_separator in the" \ " document's Front Matter if the generated excerpt is unsatisfactory." end