Setting Previous and Next buttons for proxy pages

I’m using a yml file to store information about a series of projects that I’m using to generate a series of proxy pages. So far, everything has worked pretty well, but I want the user to be able to navigate to next and previous pages.

I’ve thought of a few approaches but I’m not conversant enough with Ruby to do anything but a hack:

  • instead of using SEO-friendly slugs, use index values for each project, therefore making linking easily based on an integer value. This I could do as I saw in another example but I don’t want to give up my nice URLs.
  • add next_project_slug and previous_project_slug to each project in the YML, but that’s messy… this is my hacky solution.
  • Ideally, I could find another solution that finds the links of the ‘neighbor’ pages for my projects. It seems as though something in config.rb that would pass in locals for the neighbor slug values might work.

Am open to any ideas on a clean implementation of this. Thanks!

I am assuming you have a yaml file with projects listed in the order you want them to appear. When you iterate through the array of projects and generate the proxy pages, you can keep track of the previous and next pages. Then, you can pass in the neighbouring pages as local variables when proxies are created. That way, you can keep the SEO slugs without having to manually wire up pages.

Yes, the are in order.

That’s the strategy I would like to take, @vvasabi, but I’m unclear on how to do that.

If you can share the code you use to set up the proxies, perhaps I can help you modify it to work the way you want.

thanks @vvasabi!

Pretty much what I’ve found out in the wild:

data.projects.each_with_index do |project, index|
  proxy "/projects/#{project.slug}/index.html", "projects/project.html", :locals => { :project => project, :index => index }, :ignore => true
end```

Here you go: https://github.com/vvasabi/middleman-portfolio-example