From 50d0fc3c85feb287551f79a537c2ff81e3ecf5fa Mon Sep 17 00:00:00 2001 From: Alfred Xing Date: Tue, 4 Nov 2014 16:13:04 -0800 Subject: [PATCH] Match post.name instead of slugs and dates --- lib/jekyll/tags/post_url.rb | 26 +++----------------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/lib/jekyll/tags/post_url.rb b/lib/jekyll/tags/post_url.rb index 0f92df49..39adc51a 100644 --- a/lib/jekyll/tags/post_url.rb +++ b/lib/jekyll/tags/post_url.rb @@ -3,35 +3,15 @@ module Jekyll class PostComparer MATCHER = /^(.+\/)*(\d+-\d+-\d+)-(.*)$/ - attr_accessor :date, :slug + attr_accessor :path, :date, :slug def initialize(name) - all, path, date, slug = *name.sub(/^\//, "").match(MATCHER) + all, @path, @date, @slug = *name.sub(/^\//, "").match(MATCHER) raise ArgumentError.new("'#{name}' does not contain valid date and/or title.") unless all - @slug = path ? path + slug : slug - @date = Utils.parse_date(date, "'#{name}' does not contain valid date.") end def ==(other) - slug == post_slug(other) && - date.year == other.date.year && - date.month == other.date.month && - date.day == other.date.day - end - - private - # Construct the directory-aware post slug for a Jekyll::Post - # - # other - the Jekyll::Post - # - # Returns the post slug with the subdirectory (relative to _posts) - def post_slug(other) - path = other.name.split("/")[0...-1].join("/") - if path.nil? || path == "" - other.slug - else - path + '/' + other.slug - end + other.name.match(/^#{path}#{date}-#{slug}\.[^.]+/) end end