使用SSI或grunt将所有shtml文件编译成一个html文件

问题描述 投票:0回答:1

我正在尝试为现有项目构建实时样式指南。作为其中的一部分,我想将一个文件夹中的所有 shtml 小部件包含到一个 html 文件中。

我正在寻找的解决方案类型将遵循这种行为:

  1. 搜索小部件文件夹中的所有文件
  2. 将所有文件编译成一个 html 页面
  3. 使用文件名作为每个包含的小部件上方的标题

该项目通过 Express 服务器使用 grunt 和 SSI 运行,因此我猜有几个选项。

我发现了这个包含 grunt 的包,但是其中大部分超出了我的知识水平,所以我没能得到任何东西。

这是我迄今为止的 grunt 文件的代码:

includes: {
  files: {
    src: ['widgets/.shtml'], // Source files
    dest: 'kitchen-sink', // Destination directory
    flatten: true,
    cwd: '.',
    options: {
      silent: true,
      banner: '<!-- I am a banner <% includes.files.dest %> -->'
    }
  }
}

我可以看到这如何处理单个命名文件,但循环遍历文件夹似乎是一项更困难的任务。

欢迎任何可能的解决方案的建议。

javascript html node.js gruntjs ssi
1个回答
1
投票

最后我按照 Qualcuno 的建议使用 grunt-html-build。这非常有效,我可能会编写另一个繁重的任务来写入页面上小部件的标题。

这是我的最终代码:

htmlbuild: {
    dist: {
        src: 'kitchen_sink/kitchen-sink.shtml',
        dest: 'prod/kitchen_sink/kitchen-sink.shtml',
        options: {
            sections: {
                views: 'prod/templates/widgets/**/*.shtml',
                templates: 'prod/templates/widgets/**/*.shtml'
            }
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.