Respect user-defined name attribute in documents (#9167)

Merge pull request 9167
This commit is contained in:
Ashwin Maroli
2022-10-26 22:06:32 +05:30
committed by GitHub
parent 390b1f006b
commit 7206b7f9ef
5 changed files with 31 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
name: launcher
---
`name` defined in front matter.

View File

@@ -0,0 +1,4 @@
---
---
No `name` in front matter.

View File

@@ -159,6 +159,23 @@ class TestDocument < JekyllUnitTest
should "output its relative path as path in Liquid" do
assert_equal "_methods/configuration.md", @document.to_liquid["path"]
end
context "when rendered with Liquid" do
should "respect the front matter definition" do
site = fixture_site("collections" => ["roles"]).tap(&:process)
docs = site.collections["roles"].docs
# Ruby context: doc.basename is aliased as doc.to_liquid["name"] by default.
document = docs.detect { |d| d.relative_path == "_roles/unnamed.md" }
assert_equal "unnamed.md", document.basename
assert_equal "unnamed.md", document.to_liquid["name"]
document = docs.detect { |d| d.relative_path == "_roles/named.md" }
assert_equal "named.md", document.basename
assert_equal "launcher", document.to_liquid["name"]
end
end
end
context "a document as part of a collection with front matter defaults" do