Skip to content

Commit

Permalink
3.9-stable: allow Pages to be Excerpted (#9550)
Browse files Browse the repository at this point in the history
Merge pull request 9550
  • Loading branch information
parkr committed Feb 13, 2024
1 parent eb2c888 commit ee86ce5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
15 changes: 15 additions & 0 deletions lib/jekyll/page.rb
Expand Up @@ -183,5 +183,20 @@ def trigger_hooks(hook_name, *args)
def write?
true
end

# The Page excerpt_separator, from the YAML Front-Matter or site
# default excerpt_separator value
#
# Returns the document excerpt_separator
def excerpt_separator
(data["excerpt_separator"] || site.config["excerpt_separator"]).to_s
end

# Whether to generate an excerpt
#
# Returns true if the excerpt separator is configured.
def generate_excerpt?
!excerpt_separator.empty?
end
end
end
7 changes: 7 additions & 0 deletions test/source/page_with_excerpt.md
@@ -0,0 +1,7 @@
---
title: I am a page with an excerpt
---

I am the excerpt

I am the remainder of the page
18 changes: 18 additions & 0 deletions test/test_excerpt.rb
Expand Up @@ -10,6 +10,10 @@ def setup_post(file)
}).tap(&:read)
end

def setup_page
Page.new(@site, @site.in_source_dir, "", "page_with_excerpt.md")
end

def do_render(document)
@site.layouts = {
"default" => Layout.new(@site, source_dir("_layouts"), "simple.html"),
Expand Down Expand Up @@ -300,4 +304,18 @@ def do_render(document)
assert_equal true, @excerpt.is_a?(Jekyll::Excerpt)
end
end

context "On a page" do
setup do
clear_dest
@site = fixture_site
@page = setup_page
@excerpt = Jekyll::Excerpt.new(@page)
end


should "produce a proper excerpt" do
assert_equal @excerpt.content, "I am the excerpt\n\n"
end
end
end
4 changes: 2 additions & 2 deletions test/test_filters.rb
Expand Up @@ -809,7 +809,7 @@ def to_liquid
"The list of grouped items for '' is not an Array."
)
# adjust array.size to ignore symlinked page in Windows
qty = Utils::Platforms.really_windows? ? 14 : 15
qty = Utils::Platforms.really_windows? ? 15 : 16
assert_equal qty, g["items"].size
end
end
Expand Down Expand Up @@ -1007,7 +1007,7 @@ def to_liquid
"The list of grouped items for '' is not an Array."
)
# adjust array.size to ignore symlinked page in Windows
qty = Utils::Platforms.really_windows? ? 14 : 15
qty = Utils::Platforms.really_windows? ? 15 : 16
assert_equal qty, g["items"].size
end
end
Expand Down
1 change: 1 addition & 0 deletions test/test_site.rb
Expand Up @@ -231,6 +231,7 @@ def generate(site)
index.html
info.md
main.scss
page_with_excerpt.md
properties.html
sitemap.xml
static_files.html
Expand Down

0 comments on commit ee86ce5

Please sign in to comment.