Merge pull request #954 from maul-esel/liquid-override-path

Allow overriding "path" in YAML frontmatter
This commit is contained in:
Parker Moore 2013-04-12 15:16:11 -07:00
commit 47653381b1
5 changed files with 18 additions and 3 deletions

View File

@ -168,6 +168,15 @@ Feature: Post data
| dir | dir/ | | dir | dir/ |
| dir/nested | dir/nested/ | | dir/nested | dir/nested/ |
Scenario: Override page.path variable
Given I have a _posts directory
And I have the following post:
| title | date | path | content |
| override | 4/12/2013 | override-path.html | Custom path: {{ page.path }} |
When I run jekyll
Then the _site directory should exist
And I should see "Custom path: override-path.html" in "_site/2013/04/12/override.html"
Scenario: Disable a post from being published Scenario: Disable a post from being published
Given I have a _posts directory Given I have a _posts directory
And I have an "index.html" file that contains "Published!" And I have an "index.html" file that contains "Published!"

View File

@ -22,6 +22,12 @@ Feature: Site data
| dir | dir/about.html | | dir | dir/about.html |
| dir/nested | dir/nested/page.html | | dir/nested | dir/nested/page.html |
Scenario: Override page.path
Given I have an "override.html" page with path "custom-override.html" that contains "Custom path: {{ page.path }}"
When I run jekyll
Then the _site directory should exist
And I should see "Custom path: custom-override.html" in "_site/override.html"
Scenario: Use site.time variable Scenario: Use site.time variable
Given I have an "index.html" page that contains "{{ site.time }}" Given I have an "index.html" page that contains "{{ site.time }}"
When I run jekyll When I run jekyll

View File

@ -66,7 +66,7 @@ Given /^I have the following (draft|post)s?(?: (.*) "(.*)")?:$/ do |status, dire
end end
matter_hash = {} matter_hash = {}
%w(title layout tag tags category categories published author).each do |key| %w(title layout tag tags category categories published author path).each do |key|
matter_hash[key] = post[key] if post[key] matter_hash[key] = post[key] if post[key]
end end
matter = matter_hash.map { |k, v| "#{k}: #{v}\n" }.join.chomp matter = matter_hash.map { |k, v| "#{k}: #{v}\n" }.join.chomp

View File

@ -125,7 +125,7 @@ module Jekyll
self.data.deep_merge({ self.data.deep_merge({
"url" => self.url, "url" => self.url,
"content" => self.content, "content" => self.content,
"path" => File.join(@dir, @name).sub(/\A\//, '') }) "path" => self.data['path'] || File.join(@dir, @name).sub(/\A\//, '') })
end end
# Obtain destination path. # Obtain destination path.

View File

@ -287,7 +287,7 @@ module Jekyll
"tags" => self.tags, "tags" => self.tags,
"content" => self.content, "content" => self.content,
"excerpt" => self.excerpt, "excerpt" => self.excerpt,
"path" => File.join(@dir, '_posts', @name).sub(/\A\//, '') }) "path" => self.data['path'] || File.join(@dir, '_posts', @name).sub(/\A\//, '') })
end end
# Returns the shorthand String identifier of this Post. # Returns the shorthand String identifier of this Post.