From d64fd1e8fea9de400109cf0f3f181d590e67293f Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Fri, 12 Apr 2013 17:37:16 +0200 Subject: [PATCH 1/3] expose file path relative to source dir to liquid Fixes #633. --- lib/jekyll/page.rb | 3 ++- lib/jekyll/post.rb | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/jekyll/page.rb b/lib/jekyll/page.rb index 0de5e254..c56396a4 100644 --- a/lib/jekyll/page.rb +++ b/lib/jekyll/page.rb @@ -124,7 +124,8 @@ module Jekyll def to_liquid self.data.deep_merge({ "url" => self.url, - "content" => self.content }) + "content" => self.content, + "path" => File.join(@dir, @name).sub(/\A\//, '') }) end # Obtain destination path. diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index e040fb02..45de5267 100644 --- a/lib/jekyll/post.rb +++ b/lib/jekyll/post.rb @@ -33,6 +33,7 @@ module Jekyll # Returns the new Post. def initialize(site, source, dir, name) @site = site + @dir = dir @base = self.containing_dir(source, dir) @name = name @@ -285,7 +286,8 @@ module Jekyll "previous" => self.previous, "tags" => self.tags, "content" => self.content, - "excerpt" => self.excerpt }) + "excerpt" => self.excerpt, + "path" => File.join(@dir, @name).sub(/\A\//, '') }) end # Returns the shorthand String identifier of this Post. From dc4d7c0bf4cf20b16ad0c51040bf4aca05de9c04 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Fri, 12 Apr 2013 18:17:57 +0200 Subject: [PATCH 2/3] fix path for posts: must include "_posts" --- lib/jekyll/post.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/post.rb b/lib/jekyll/post.rb index 45de5267..1da37001 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, @name).sub(/\A\//, '') }) + "path" => File.join(@dir, '_posts', @name).sub(/\A\//, '') }) end # Returns the shorthand String identifier of this Post. From 5a92a73010eb810eb0f185645f1023022522b7c6 Mon Sep 17 00:00:00 2001 From: "maul.esel" Date: Fri, 12 Apr 2013 18:18:17 +0200 Subject: [PATCH 3/3] add cucumber tests for page.path variable --- features/post_data.feature | 15 +++++++++++++++ features/site_data.feature | 13 +++++++++++++ 2 files changed, 28 insertions(+) diff --git a/features/post_data.feature b/features/post_data.feature index 61732f90..6ff48d6c 100644 --- a/features/post_data.feature +++ b/features/post_data.feature @@ -153,6 +153,21 @@ Feature: Post data And I should see "Post categories: scifi and movies" in "_site/scifi/movies/2009/03/27/star-wars.html" And I should see "Post categories: scifi and movies" in "_site/scifi/movies/2013/03/17/star-trek.html" + Scenario Outline: Use post.path variable + Given I have a /_posts directory + And I have the following post in "": + | title | type | date | content | + | my-post | html | 4/12/2013 | Source path: {{ page.path }} | + When I run jekyll + Then the _site directory should exist + And I should see "Source path: _posts/2013-04-12-my-post.html" in "_site//2013/04/12/my-post.html" + + Examples: + | dir | path_prefix | + | . | | + | dir | dir/ | + | dir/nested | dir/nested/ | + 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 0a0b1a7e..36b0f861 100644 --- a/features/site_data.feature +++ b/features/site_data.feature @@ -9,6 +9,19 @@ Feature: Site data Then the _site directory should exist And I should see "Contact: email@me.com" in "_site/contact.html" + Scenario Outline: Use page.path variable in a page + Given I have a directory + And I have a "" page that contains "Source path: {{ page.path }}" + When I run jekyll + Then the _site directory should exist + And I should see "Source path: " in "_site/" + + Examples: + | dir | path | + | . | index.html | + | dir | dir/about.html | + | dir/nested | dir/nested/page.html | + Scenario: Use site.time variable Given I have an "index.html" page that contains "{{ site.time }}" When I run jekyll