Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable page excerpts by default #8222

Merged
merged 2 commits into from Jun 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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