I have a giant JSON array of every US state and city, along with other data about each of them. I'd like to iterate over the JSON and output a tree structure like this:
I'd have two layouts:
So far, I haven't found a great way to do this. A lot of static gens seem to have the ability to use JSON for meta data within content, but not for the primary source of content.
thanks!
The Middleman static site generator supports this. You use their dynamic pages to create a list of the pages to create. The data comes from their data file feature. Here are the links to the pages explaining these
https://middlemanapp.com/advanced/dynamic_pages/ https://middlemanapp.com/advanced/data_files/
You would do something like have states.yml containing the state and city data
- states
- name: Alabama
cities:
- name: Abbeville
pop: X
- name: Adamsville
pop: Y
and then create the proxy pages e.g.
data.states.each do |state|
proxy "/#{state.name}/index.html", "templates/state.html", :locals => {state: state}
state.cities.each do |city|
proxy "/#{state.name}/#{city.name}/index.html", "/templates/city.html", :locals => {state: state, city: city}
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With