class Jekyll::Excerpt
def data
Fetch YAML front-matter data from related doc, without layout key
def data @data ||= doc.data.dup @data.delete("layout") @data.delete("excerpt") @data end
def endtag_regex_stash(tag_name)
def endtag_regex_stash(tag_name) @endtag_regex_stash ||= {} @endtag_regex_stash[tag_name] ||= %r!{%-?\s*end#{tag_name}.*?\s*-?%}!m end
def extract_excerpt(doc_content)
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
def extract_markdown_link_reference_definitions(head, tail)
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
def id
e.g. /2008/11/05/my-awesome-doc
The UID for this doc (useful in feeds).
def id "#{doc.id}#excerpt" end
def include?(something)
Check if excerpt includes a string
def include?(something) output&.include?(something) || content.include?(something) end
def initialize(doc)
doc - The Document.
Initialize this Excerpt instance.
def initialize(doc) self.doc = doc self.content = extract_excerpt(doc.content) end
def inspect
def inspect "<#{self.class} id=#{id}>" end
def liquid_block?(tag_name)
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
def output
def output @output ||= Renderer.new(doc.site, self, site.site_payload).run end
def path
'Path' of the excerpt.
def path File.join(doc.path, "#excerpt") end
def place_in_layout?
def place_in_layout? false end
def print_build_warning
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
def relative_path
'Relative Path' of the excerpt.
def relative_path @relative_path ||= File.join(doc.relative_path, "#excerpt") end
def render_with_liquid?
def render_with_liquid? return false if data["render_with_liquid"] == false !(coffeescript_file? || yaml_file? || !Utils.has_liquid_construct?(content)) end
def sanctify_liquid_tags(head)
append appropriate closing tag(s) (for each Liquid block), to the `head` if the
def sanctify_liquid_tags(head) modified = false tag_names = head.scan(LIQUID_TAG_REGEX) tag_names.flatten! tag_names.reverse_each do |tag_name| next unless liquid_block?(tag_name) next if endtag_regex_stash(tag_name).match?(head) modified = true head << "\n{% end#{tag_name} %}" end print_build_warning if modified head end
def to_liquid
def to_liquid Jekyll::Drops::ExcerptDrop.new(self) end
def to_s
def to_s output || content end
def trigger_hooks(*); end
def trigger_hooks(*); end