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