Disable page excerpts by default (#8222)

Merge pull request 8222
This commit is contained in:
Ashwin Maroli 2020-06-04 14:27:10 +05:30 committed by GitHub
parent 4b57a4187e
commit 8b22c9dcd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 5 deletions

View File

@ -35,6 +35,11 @@ If you have a lot of pages, you can organize them into subfolders. The same subf
You might want to have a particular folder structure for your source files that changes for the built site. With [permalinks](/docs/permalinks) you have full control of the output URL.
## Excerpts for pages
From Jekyll 4.1.1 onwards, one can *choose* to generate excerpts for their pages by setting `page_excerpts` to `true` in their
config file.
## Liquid Representation
From Jekyll 4.1 onwards, there is a minor change in how instances of `Jekyll::Page` are exposed to layouts and other Liquid

View File

@ -217,13 +217,14 @@ module Jekyll
end
def excerpt_separator
@excerpt_separator ||= (data["excerpt_separator"] || site.config["excerpt_separator"]).to_s
@excerpt_separator ||= data["excerpt_separator"] || site.config["excerpt_separator"] || ""
end
def excerpt
return if excerpt_separator.empty? || !site.config["page_excerpts"]
return data["excerpt"] unless self.class == Jekyll::Page
data["excerpt"] ||= Jekyll::PageExcerpt.new(self).to_liquid unless excerpt_separator.empty?
data["excerpt"] ||= Jekyll::PageExcerpt.new(self).to_liquid
end
end
end

View File

@ -125,7 +125,7 @@ class TestPage < JekyllUnitTest
attrs = {
:content => "All the properties.\n",
:dir => "/properties/",
:excerpt => "All the properties.\n",
:excerpt => nil,
:foo => "bar",
:layout => "default",
:name => "properties.html",
@ -405,9 +405,15 @@ class TestPage < JekyllUnitTest
end
context "read-in by default" do
should "expose an excerpt to Liquid templates" do
should "not expose an excerpt to Liquid templates" do
page = setup_page("/contacts", "bar.html")
assert_equal "Contact Information\n", page.to_liquid["excerpt"]
assert_nil page.to_liquid["excerpt"]
end
should "expose an excerpt to Liquid templates if site is configured to" do
configured_site = fixture_site("page_excerpts" => true)
test_page = Jekyll::Page.new(configured_site, source_dir, "/contacts", "bar.html")
assert_equal "Contact Information\n", test_page.to_liquid["excerpt"]
end
end