Skip to content

Instantly share code, notes, and snippets.

@elvisoliveira
Last active December 13, 2024 19:12
Show Gist options
  • Select an option

  • Save elvisoliveira/56e3182b20a4915519d39aa284ad491c to your computer and use it in GitHub Desktop.

Select an option

Save elvisoliveira/56e3182b20a4915519d39aa284ad491c to your computer and use it in GitHub Desktop.
Simple data pagination on Ruby's middleman SSG
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
---
- 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