Add more methods to Jekyll::Page that makes it more like a Document

This commit is contained in:
Parker Moore
2024-02-13 22:49:45 -08:00
parent f714b69e5e
commit e8a02e02db
2 changed files with 44 additions and 0 deletions

View File

@@ -198,5 +198,28 @@ module Jekyll
def generate_excerpt?
!excerpt_separator.empty?
end
# Determine whether the page is a YAML file.
#
# Returns true if the extname is either .yml or .yaml, false otherwise.
def yaml_file?
%w(.yaml .yml).include?(extname)
end
def previous_doc
end
def next_doc
end
def collection
Struct.new(:label).new("")
end
def id
@id ||= File.join(
*[@dir, (data["slug"] || File.basename(basename, ".*"))].map(&:to_s).reject(&:empty?)
)
end
end
end

View File

@@ -317,5 +317,26 @@ class TestExcerpt < JekyllUnitTest
should "produce a proper excerpt" do
assert_equal @excerpt.content, "I am the excerpt\n\n"
end
should "render" do
assert_equal @excerpt.output, "<p>I am the excerpt</p>\n\n"
end
should "support the drop" do
assert_equal @excerpt.to_liquid.to_h, {
"layout": nil,
"excerpt": nil,
"path": "page_with_excerpt.md/#excerpt",
"previous": nil,
"next": nil,
"output": "<p>I am the excerpt</p>\n\n",
"content": "<p>I am the excerpt</p>\n\n",
"collection": "",
"id": "/page_with_excerpt#excerpt",
"url": "/page_with_excerpt.html",
"relative_path": "page_with_excerpt.md/#excerpt",
"title": "I am a page with an excerpt"
}
end
end
end