Skip to content

Commit

Permalink
Disable page excerpts by default (#8222)
Browse files Browse the repository at this point in the history
Merge pull request 8222
  • Loading branch information
ashmaroli committed Jun 4, 2020
1 parent 4b57a41 commit 8b22c9d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
5 changes: 5 additions & 0 deletions docs/_docs/pages.md
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lib/jekyll/page.rb
Expand Up @@ -217,13 +217,14 @@ def write?
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
12 changes: 9 additions & 3 deletions test/test_page.rb
Expand Up @@ -125,7 +125,7 @@ def do_render(page)
attrs = {
:content => "All the properties.\n",
:dir => "/properties/",
:excerpt => "All the properties.\n",
:excerpt => nil,
:foo => "bar",
:layout => "default",
:name => "properties.html",
Expand Down Expand Up @@ -405,9 +405,15 @@ def do_render(page)
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

Expand Down

0 comments on commit 8b22c9d

Please sign in to comment.