From 968f3b0911245de58a8c4a19aae115baa19b6992 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Sat, 13 Apr 2013 00:05:49 +0200 Subject: [PATCH 1/2] allow overriding page.path in YAML frontmatter --- lib/jekyll/page.rb | 2 +- lib/jekyll/post.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index c56396a4..80f5b884 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -125,7 +125,7 @@ module Jekyll self.data.deep_merge({ "url" => self.url, "content" => self.content, - "path" => File.join(@dir, @name).sub(/\A\//, '') }) + "path" => self.data['path'] || File.join(@dir, @name).sub(/\A\//, '') }) end # Obtain destination path. diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index 1da37001..5ea56898 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -287,7 +287,7 @@ module Jekyll "tags" => self.tags, "content" => self.content, "excerpt" => self.excerpt, - "path" => File.join(@dir, '_posts', @name).sub(/\A\//, '') }) + "path" => self.data['path'] || File.join(@dir, '_posts', @name).sub(/\A\//, '') }) end # Returns the shorthand String identifier of this Post. From c20fc036042aa5092f22981b264a9d53ee4dbd9f Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Sat, 13 Apr 2013 00:06:09 +0200 Subject: [PATCH 2/2] add cucumber tests for overriding path --- features/post_data.feature | 9 +++++++++ features/site_data.feature | 6 ++++++ features/step_definitions/jekyll_steps.rb | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/features/post_data.feature b/features/post_data.feature index 6ff48d6c..04c385ac 100644 --- a/features/post_data.feature +++ b/features/post_data.feature @@ -168,6 +168,15 @@ Feature: Post data | dir | dir/ | | 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 Given I have a _posts directory And I have an "index.html" file that contains "Published!" diff --git a/features/site_data.feature b/features/site_data.feature index 36b0f861..47f34ec0 100644 --- a/features/site_data.feature +++ b/features/site_data.feature @@ -22,6 +22,12 @@ Feature: Site data | dir | dir/about.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 Given I have an "index.html" page that contains "{{ site.time }}" When I run jekyll diff --git a/features/step_definitions/jekyll_steps.rb b/features/step_definitions/jekyll_steps.rb index 05629e77..fd58679d 100644 --- a/features/step_definitions/jekyll_steps.rb +++ b/features/step_definitions/jekyll_steps.rb @@ -66,7 +66,7 @@ Given /^I have the following (draft|post)s?(?: (.*) "(.*)")?:$/ do |status, dire end 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] end matter = matter_hash.map { |k, v| "#{k}: #{v}\n" }.join.chomp