Skip to content

Commit

Permalink
Refactor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
oriolgual committed Oct 6, 2010
1 parent 76155cb commit a6e230d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/models/archive_page.rb
Expand Up @@ -11,10 +11,16 @@ class ArchivePage < Page
}

def child_url(child)
if child.request and %w{ArchiveDayIndexPage ArchiveMonthIndexPage ArchiveYearIndexPage}.include?(child.class_name)
clean_url child.request.request_uri
@year, @month, @day = $1, ($2 || 1).to_i, ($3 || 1).to_i if child.request and child.request.request_uri =~ %r{/(\d{4})(?:/(\d{2})(?:/(\d{2}))?)?/?$}
date = (@year ? Date.new(@year.to_i, @month, @day) : (child.published_at || Time.now))

if ArchiveYearIndexPage === child
clean_url "#{ url }/#{ date.strftime '%Y' }/"
elsif ArchiveMonthIndexPage === child
clean_url "#{ url }/#{ date.strftime '%Y/%m' }/"
elsif ArchiveDayIndexPage === child
clean_url "#{ url }/#{ date.strftime '%Y/%m/%d/' }/"
else
date = child.published_at || Time.now
clean_url "#{ url }/#{ date.strftime '%Y/%m/%d' }/#{ child.slug }"
end
end
Expand Down

0 comments on commit a6e230d

Please sign in to comment.