简体   繁体   中英

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. 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. 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. What static site generators support this kind of workflow?

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.

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. You create a file for each "DataObject" referred to in the question, and Jekyll runs through them and generates pages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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