Expose `basename` from `document.rb` as `name` to Liquid templates (#8761)

Merge pull request 8761
This commit is contained in:
JJ 2022-04-01 10:24:55 -03:00 committed by GitHub
parent 310459370a
commit 776748e13f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 0 deletions

View File

@ -27,6 +27,18 @@ Feature: Post data
And the _site directory should exist
And I should see "Post url: /2009/03/27/star-wars.html" in "_site/2009/03/27/star-wars.html"
Scenario: Use page.name variable
Given I have a _posts directory
And I have a _layouts directory
And I have the following post:
| title | date | layout | content |
| Star Wars | 2009-03-27 | simple | Luke, I am your father. |
And I have a simple layout that contains "Page name: {{ page.name }}"
When I run jekyll build
Then I should get a zero exit status
And the _site directory should exist
And I should see "Page name: 2009-03-27-star-wars.markdown" in "_site/2009/03/27/star-wars.html"
Scenario: Use post.date variable
Given I have a _posts directory
And I have a _layouts directory

View File

@ -12,6 +12,7 @@ module Jekyll
mutable false
delegate_method_as :relative_path, :path
delegate_method_as :basename, :name
private delegate_method_as :data, :fallback_data
delegate_methods :id, :output, :content, :to_s, :relative_path, :url, :date

View File

@ -14,6 +14,10 @@ module Jekyll
def excerpt
nil
end
def name
@obj.doc.basename
end
end
end
end

View File

@ -665,6 +665,7 @@ class TestFilters < JekyllUnitTest
should "convert drop to json" do
@filter.site.read
expected = {
"name" => "2008-02-02-published.markdown",
"path" => "_posts/2008-02-02-published.markdown",
"previous" => nil,
"output" => nil,