Last active
December 13, 2024 19:12
-
-
Save elvisoliveira/56e3182b20a4915519d39aa284ad491c to your computer and use it in GitHub Desktop.
Simple data pagination on Ruby's middleman SSG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| redirect "photos.html", to: "photos_1.html" | |
| ready do | |
| photos = @app.data.photos | |
| start_index = 0 | |
| page_num = 1 | |
| per_page = 8 | |
| while start_index <= photos.size | |
| proxy "photos_#{page_num}.html", "gallery.html", :locals => { | |
| :photos => photos.slice(start_index, per_page), | |
| :current_page => page_num, | |
| :total_pages => photos.size.fdiv(per_page).ceil | |
| } | |
| start_index += per_page | |
| page_num += 1 | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <h1>Photos</h1> | |
| <table> | |
| <tbody> | |
| <% photos.each_slice(4) do |photo_row| %> | |
| <tr> | |
| <% photo_row.each do |photo| %> | |
| <td valign="top"> | |
| <% link_to "/images/gallery/#{photo.id}", :rel => 'lightbox' do %> | |
| <%= image_tag "gallery/#{photo.id}", :width => '150' %> | |
| <% end %> | |
| </td> | |
| <% end %> | |
| </tr> | |
| <% end %> | |
| <tr> | |
| <td colspan="4"> | |
| <% if current != 1 %> | |
| <span><%= link_to 'Anterior', "/fotos_#{current - 1}.html" %></span> | |
| <% end %> | |
| <% (1..(total)).to_a.each do |page_num| %> | |
| <span class="<%= 'active' if current == page_num %>"><%= link_to page_num, "/fotos_#{page_num}.html" %></span> | |
| <% end %> | |
| <% if current < total %> | |
| <span><%= link_to 'Próximo', "/fotos_#{current + 1}.html" %></span> | |
| <% end %> | |
| </td> | |
| </tr> | |
| </tbody> | |
| </table> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| - id: 448970252_7892756390747615_7868681486103445415_n.jpg | |
| - id: 448999905_7892756380747616_3749143020759625347_n.jpg | |
| - id: 448999905_7892756387414282_581577080674223399_n.jpg | |
| - id: 449000436_7892756407414280_3940848664023003364_n.jpg | |
| - id: 449009087_7892756397414281_3110121629585911972_n.jpg | |
| - id: 449042676_7892756377414283_8182958457791327561_n.jpg | |
| - id: 449066868_7892756384080949_5094358673649276250_n.jpg | |
| - id: 449087964_7892756400747614_4315544168763210858_n.jpg | |
| - id: 449089910_7889668157723105_4088799346710329395_n.jpg | |
| - id: 449090345_7892756620747592_2205314037206939018_n.jpg | |
| - id: 449090694_7889669027723018_7672883594657392648_n.jpg | |
| - id: 449133588_7892756404080947_3606718287020836489_n.jpg | |
| - id: 449139370_7892756394080948_1051249615376192228_n.jpg | |
| - id: 449144174_7889668394389748_8146916996209712707_n.jpg | |
| - id: 449149083_7892756600747594_1051892795528060546_n.jpg | |
| - id: 449165221_7889668151056439_796245988427328527_n.jpg | |
| - id: 449223159_7889668827723038_7177569559245200276_n.jpg | |
| - id: 449256605_7889668161056438_1818529128334343178_n.jpg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment