diff --git a/app.rb b/app.rb index 94c354d8..176f11f2 100644 --- a/app.rb +++ b/app.rb @@ -35,7 +35,13 @@ get '/?' do end get '/browse' do - @sites = Site.order(:id.desc).filter(~{updated_at: nil}).all + @current_page = params[:current_page] || 1 + @current_page = @current_page.to_i + site_dataset = Site.order(:id.desc).filter(~{updated_at: nil}).paginate(@current_page, 100) + + @page_count = site_dataset.page_count + + @sites = site_dataset.all slim :browse end diff --git a/views/browse.slim b/views/browse.slim index 9e092a04..22195ed1 100644 --- a/views/browse.slim +++ b/views/browse.slim @@ -15,3 +15,15 @@ .span3.text-right p style="margin-right: 20px; margin-top: 10px" #{site.hits} hits
last updated #{site.updated_at.ago} a href="http://#{site.username}.neocities.org" target="_blank": img src="/site_screenshots/#{ENV['RACK_ENV'] == 'development' ? 'victoria' : site.username}.jpg" + +- if @page_count > 1 + .pagination.pagination-large.text-center + ul + - if @current_page != 1 + li: a href="/browse?current_page=#{@current_page - 1}": i.icon-arrow-left style="font-size: 12pt" + + - 1.upto(@page_count) do |num| + li class="#{"active" if num == @current_page}": a href="/browse?current_page=#{num}" #{num} + + - if @current_page != @page_count + li: a href="/browse?current_page=#{@current_page + 1}": i.icon-arrow-right style="font-size: 12pt" \ No newline at end of file