简体   繁体   English

数据支持的 static 站点生成器?

[英]Data-backed static site generator?

I am in the process of selecting a static site generator and have not yet been able to find one that meets my specific use case.我正在选择 static 站点生成器,但尚未找到符合我特定用例的站点生成器。 Here's a simplified version of what I'm looking for:这是我正在寻找的简化版本:

With the exception of a few pages, every page looks something like this:除了几页外,每一页看起来都是这样的:

<html>
  <head>
    <title><!-- Title differs based on page --></title>
  </head>
  <body>
    <ul>
      <!-- List entries here differ based on the page -->
    </ul>
  </body>
</html>

As far as I can tell, the "standard" way of doing this in a static site generator would be to create a template file for the overall HTML and then create a page file (using said template) for each specific page.据我所知,在 static 站点生成器中执行此操作的“标准”方法是为整个 HTML 创建一个模板文件,然后为每个特定页面创建一个页面文件(使用所述模板)。 I feel like this unnecessarily clutters up the development directory when every page is the same except for the data it displays.当除了显示的数据之外的每个页面都相同时,我觉得这不必要地弄乱了开发目录。

What I would like is for this to be entirely data-driven instead.我想要的是完全由数据驱动。 That is, I would like create a template file based on the above and then a data file something along the lines of this:也就是说,我想根据上面的内容创建一个模板文件,然后创建一个数据文件,如下所示:

TemplateToUse = 'MyTemplateFile.html'

DataObjects =
[
  {
    OutputFilename = 'Page1.html',
    PageData = {
      Title = 'Page 1',
      ListEntries = [ ... ]
    }
  },
  {
    OutputFilename = 'Page2.html',
    PageData = {
      Title = 'Page 2',
      ListEntries = [ ... ]
    }
  },
]

The static site generator would consume this and output each of the pages, passing the data to the template for each one. static 站点生成器将使用这个和 output 每个页面,将数据传递给每个页面的模板。 What static site generators support this kind of workflow?哪些 static 站点生成器支持这种工作流程?

It looks like Jekyll's Generators would accomplish this task, but I would be more interested in something that 1) is statically typed and 2) requires less custom code.看起来 Jekyll 的生成器可以完成这项任务,但我对 1) 静态类型和 2) 需要较少自定义代码的东西更感兴趣。

While I haven't found an equally powerful, statically typed option, it looks like Jekyll's Collections functionality is exactly what you're looking for.虽然我还没有找到同样强大的静态类型选项,但看起来 Jekyll 的Collections功能正是您正在寻找的。 You create a file for each "DataObject" referred to in the question, and Jekyll runs through them and generates pages.您为问题中提到的每个“DataObject”创建一个文件,Jekyll 会运行它们并生成页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM