Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add :i_day and :i_month permalink values so you can get urls like /20…

…10/6/1/title
  • Loading branch information...
commit e8d119ef0a38024a7188e4a96b8d23fbf8574ecb 1 parent a4f3f5c
@technoweenie technoweenie authored
Showing with 26 additions and 13 deletions.
  1. +3 −1 lib/jekyll/post.rb
  2. +23 −12 test/test_post.rb
View
4 lib/jekyll/post.rb
@@ -124,9 +124,11 @@ def url
"month" => date.strftime("%m"),
"day" => date.strftime("%d"),
"title" => CGI.escape(slug),
+ "i_day" => date.strftime("%d").to_i.to_s,
+ "i_month" => date.strftime("%m").to_i.to_s,
"categories" => categories.join('/')
}.inject(template) { |result, token|
- result.gsub(/:#{token.first}/, token.last)
+ result.gsub(/:#{Regexp.escape token.first}/, token.last)
}.gsub(/\/\//, "/")
end
View
35 test/test_post.rb
@@ -18,10 +18,10 @@ def do_render(post)
end
should "ensure valid posts are valid" do
- assert Post.valid?("2008-10-19-foo-bar.textile")
- assert Post.valid?("foo/bar/2008-10-19-foo-bar.textile")
+ assert Post.valid?("2008-09-09-foo-bar.textile")
+ assert Post.valid?("foo/bar/2008-09-09-foo-bar.textile")
- assert !Post.valid?("lol2008-10-19-foo-bar.textile")
+ assert !Post.valid?("lol2008-09-09-foo-bar.textile")
assert !Post.valid?("blah")
end
@@ -31,7 +31,7 @@ def do_render(post)
@post.site = @site
@real_file = "2008-10-18-foo-bar.textile"
- @fake_file = "2008-10-19-foo-bar.textile"
+ @fake_file = "2008-09-09-foo-bar.textile"
@source = source_dir('_posts')
end
@@ -39,17 +39,17 @@ def do_render(post)
@post.categories = []
@post.process(@fake_file)
- assert_equal Time.parse("2008-10-19"), @post.date
+ assert_equal Time.parse("2008-09-09"), @post.date
assert_equal "foo-bar", @post.slug
assert_equal ".textile", @post.ext
- assert_equal "/2008/10/19", @post.dir
- assert_equal "/2008/10/19/foo-bar", @post.id
+ assert_equal "/2008/09/09", @post.dir
+ assert_equal "/2008/09/09/foo-bar", @post.id
end
should "create url based on date and title" do
@post.categories = []
@post.process(@fake_file)
- assert_equal "/2008/10/19/foo-bar.html", @post.url
+ assert_equal "/2008/09/09/foo-bar.html", @post.url
end
should "CGI escape urls" do
@@ -106,7 +106,7 @@ def do_render(post)
should "process the url correctly" do
assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
- assert_equal "/2008/10/19/foo-bar.html", @post.url
+ assert_equal "/2008/09/09/foo-bar.html", @post.url
end
end
@@ -118,7 +118,7 @@ def do_render(post)
should "process the url correctly" do
assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
- assert_equal "/beer/2008/10/19/foo-bar.html", @post.url
+ assert_equal "/beer/2008/09/09/foo-bar.html", @post.url
end
end
@@ -131,7 +131,7 @@ def do_render(post)
should "process the url correctly" do
assert_equal "/:categories/:year/:month/:day/:title.html", @post.template
- assert_equal "/food/beer/2008/10/19/foo-bar.html", @post.url
+ assert_equal "/food/beer/2008/09/09/foo-bar.html", @post.url
end
end
@@ -155,7 +155,18 @@ def do_render(post)
should "process the url correctly" do
assert_equal "/:categories/:year/:month/:day/:title/", @post.template
- assert_equal "/2008/10/19/foo-bar/", @post.url
+ assert_equal "/2008/09/09/foo-bar/", @post.url
+ end
+ end
+
+ context "with custom date permalink" do
+ setup do
+ @post.site.permalink_style = '/:categories/:year/:i_month/:i_day/:title/'
+ @post.process(@fake_file)
+ end
+
+ should "process the url correctly" do
+ assert_equal "/2008/9/9/foo-bar/", @post.url
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.