gpt4 book ai didi

middleman - 从 JSON 数组生成静态站点

转载 作者:行者123 更新时间:2023-12-02 03:11:18 24 4
gpt4 key购买 nike

我有一个包含美国每个州和城市的巨大 JSON 数组,以及关于每个州和城市的其他数据。我想遍历 JSON 并输出这样的树结构:

  1. [阿拉巴马州]
    • index.html
    • [阿布维尔]
      • index.html
    • [亚当斯维尔]
      • index.html
  2. [阿拉斯加]
    • index.html
    • [安克雷奇]
      • index.html
    • [费尔类克斯]
      • index.html
  3. ...等等

我有两种布局:

  1. state.html
  2. city.html

到目前为止,我还没有找到一个很好的方法来做到这一点。许多静态类似乎能够将 JSON 用于内容中的元数据,但不能用于内容的主要来源。

谢谢!

最佳答案

Middleman 静态站点生成器支持这一点。您使用他们的动态页面来创建要创建的页面列表。数据来自他们的数据文件功能。以下是解释这些页面的链接

https://middlemanapp.com/advanced/dynamic_pages/ https://middlemanapp.com/advanced/data_files/

你会做一些事情,比如让 states.yml 包含州和城市数据

- states
- name: Alabama
cities:
- name: Abbeville
pop: X
- name: Adamsville
pop: Y

然后创建代理页面,例如

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

关于middleman - 从 JSON 数组生成静态站点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39836406/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com