我基本上是在构建一个快速而肮脏的课程目录,其中包含多个分层类别和属于这些类别的不同级别的课程。
在旧的实现中,每个主要类别都是其自己的 HTML 页面,与该类别相关的所有课程都只是以 html 格式写入该页面。目录过去主要是静态的,因此效果很好,但是现在可能会更频繁地添加课程和类别,并且将来某些用户视图选项可能会更改/扩展。
我想我会将所有原始数据(课程和目录结构)分离成 JSON,然后根据这些数据生成视图。我认为这样可以更轻松地维护内容,而无需处理适当的 CMS 或数据库。每当我需要添加一门课程时,我都会将其放入 json 文件中。
第一个问题:你会推荐这个吗?
第二个问题:如果您认为使用 JSON 是一个好主意,您是否会将课程的分类结构分离为两个 JSON 文件,然后使用 JS 操作它们?或者您是否会拥有一个 JSON,其中包含嵌入目录类别结构中的课程数据?
这是我正在考虑的一个示例。也许在将它们输出到 HTML 列表视图之前,我会使用 Underscore 正确合并这两个数据(课程推送到适当类别中的“课程”数组中)。
// JSON of categorical STRUCTURE / HIERARCHY
{
"catalog":{
"name":"Course Catalog",
"categories":[
{
"name":"Category A",
"categories":[
{
"name":"Category A1",
"categories":[
{"name":"Category A1a"}
]
},{
"name":"Category A2",
"categories":[
{"name":"Category A2a"},
{"name":"Category A2b"},
{"name":"Category A2c"}
]
},{
"name":"Category A3",
"categories":[
{"name":"Category A3a"},
{"name":"Category A3b"},
{"name":"Category A3c"}
]
}
]
},{
"name":"Category B"
},{
"name":"Category C"
}
]
}
}
// JSON array of all courses (to be plugged into the structure later through code,
// then output to HTML as nested lists etc.)
{
"courses":[
{
"name":"Course AAA",
"category":"Category A1a",
"abstract":"Some sort of short string description.",
"description":"Some sort of longer string description that will be used in the object."
},
{
"name":"Course BBB",
"category":"Category A1b",
"abstract":"Some sort of short string description.",
"description":"Some sort of longer string description that will be used in the object."
},
{
"name":"Course CCC",
"category":"Category B",
"abstract":"Some sort of short string description.",
"description":"Some sort of longer string description that will be used in the object."
},
]
}