Make page excerpts consistent with doc excerpts (#8236)

Merge pull request 8236
This commit is contained in:
Ashwin Maroli
2020-06-17 18:56:53 +05:30
committed by GitHub
parent c78ecc8d82
commit ba29de02d4
7 changed files with 63 additions and 27 deletions

View File

@@ -49,6 +49,7 @@ module Jekyll
process(name)
read_yaml(PathManager.join(base, dir), name)
generate_excerpt if site.config["page_excerpts"]
data.default_proc = proc do |_, key|
site.frontmatter_defaults.find(relative_path, type, key)
@@ -185,14 +186,25 @@ module Jekyll
end
def excerpt_separator
@excerpt_separator ||= data["excerpt_separator"] || site.config["excerpt_separator"] || ""
@excerpt_separator ||= (data["excerpt_separator"] || site.config["excerpt_separator"]).to_s
end
def excerpt
return if excerpt_separator.empty? || !site.config["page_excerpts"]
return data["excerpt"] unless self.class == Jekyll::Page && html?
return @excerpt if defined?(@excerpt)
data["excerpt"] ||= Jekyll::PageExcerpt.new(self).to_liquid
@excerpt = data["excerpt"]&.to_s
end
def generate_excerpt?
!excerpt_separator.empty? && self.class == Jekyll::Page && html?
end
private
def generate_excerpt
return unless generate_excerpt?
data["excerpt"] ||= Jekyll::PageExcerpt.new(self)
end
end
end

View File

@@ -2,15 +2,14 @@
module Jekyll
class PageExcerpt < Excerpt
attr_reader :output, :doc
attr_reader :doc
alias_method :id, :relative_path
# The Liquid representation of this instance is simply the rendered output string.
alias_method :to_liquid, :output
EXCERPT_ATTRIBUTES = (Page::ATTRIBUTES_FOR_LIQUID - %w(excerpt)).freeze
private_constant :EXCERPT_ATTRIBUTES
def initialize(doc)
super
self.output = Renderer.new(site, self, site.site_payload).run
def to_liquid
@to_liquid ||= doc.to_liquid(EXCERPT_ATTRIBUTES)
end
def render_with_liquid?