Match post.name instead of slugs and dates
This commit is contained in:
parent
ab8441259e
commit
50d0fc3c85
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue