Expose `basename` from `document.rb` as `name` to Liquid templates (#8761)
Merge pull request 8761
This commit is contained in:
parent
310459370a
commit
776748e13f
|
@ -27,6 +27,18 @@ Feature: Post data
|
||||||
And the _site directory should exist
|
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"
|
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
|
Scenario: Use post.date variable
|
||||||
Given I have a _posts directory
|
Given I have a _posts directory
|
||||||
And I have a _layouts directory
|
And I have a _layouts directory
|
||||||
|
|
|
@ -12,6 +12,7 @@ module Jekyll
|
||||||
mutable false
|
mutable false
|
||||||
|
|
||||||
delegate_method_as :relative_path, :path
|
delegate_method_as :relative_path, :path
|
||||||
|
delegate_method_as :basename, :name
|
||||||
private delegate_method_as :data, :fallback_data
|
private delegate_method_as :data, :fallback_data
|
||||||
|
|
||||||
delegate_methods :id, :output, :content, :to_s, :relative_path, :url, :date
|
delegate_methods :id, :output, :content, :to_s, :relative_path, :url, :date
|
||||||
|
|
|
@ -14,6 +14,10 @@ module Jekyll
|
||||||
def excerpt
|
def excerpt
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def name
|
||||||
|
@obj.doc.basename
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -665,6 +665,7 @@ class TestFilters < JekyllUnitTest
|
||||||
should "convert drop to json" do
|
should "convert drop to json" do
|
||||||
@filter.site.read
|
@filter.site.read
|
||||||
expected = {
|
expected = {
|
||||||
|
"name" => "2008-02-02-published.markdown",
|
||||||
"path" => "_posts/2008-02-02-published.markdown",
|
"path" => "_posts/2008-02-02-published.markdown",
|
||||||
"previous" => nil,
|
"previous" => nil,
|
||||||
"output" => nil,
|
"output" => nil,
|
||||||
|
|
Loading…
Reference in New Issue