Querying proxy pages by locals?

So, I’m trying to generate ‘next page’ and ‘previous page’ links in a site I’m building based on a chapter property in the frontmatter. So far, I’ve got this line in my helpers block in my config.rb:

query = sitemap.where(:chapter => chapter-1)

But, there’s multiple copies of each page in the Middleman tree, because each actual Markdown file is turned into multiple proxies, with different locals. Is there any way I can query for a specific value in the locals hash?

query = sitemap.resources.select {|r| r.metadata[:locals][:chapter] == chapter - 1 }

Thanks, you’re a legend.