Merge pull request #3058 from alfredxing/fix-post-url-equality

This commit is contained in:
Parker Moore 2014-11-16 20:19:37 -08:00
commit 687b9cdf19
1 changed files with 23 additions and 4 deletions

View File

@ -3,16 +3,22 @@ module Jekyll
class PostComparer
MATCHER = /^(.+\/)*(\d+-\d+-\d+)-(.*)$/
attr_accessor :date, :slug
attr_reader :path, :date, :slug, :name
def initialize(name)
all, path, date, slug = *name.sub(/^\//, "").match(MATCHER)
@name = name
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.")
@name_regex = /^#{path}#{date}-#{slug}\.[^.]+/
end
def ==(other)
other.name.match(@name_regex)
end
def deprecated_equality(other)
date = Utils.parse_date(name, "'#{name}' does not contain valid date and/or title.")
slug == post_slug(other) &&
date.year == other.date.year &&
date.month == other.date.month &&
@ -59,6 +65,19 @@ eos
end
end
# New matching method did not match, fall back to old method
# with deprecation warning if this matches
site.posts.each do |p|
if @post.deprecated_equality p
Jekyll::Deprecator.deprecation_message "A call to '{{ post_url #{name} }}' did not match " +
"a post using the new matching method of checking name " +
"(path-date-slug) equality. Please make sure that you " +
"change this tag to match the post's name exactly."
return p.url
end
end
raise ArgumentError.new <<-eos
Could not find post "#{@orig_post}" in tag 'post_url'.