【问题标题】:Paths of the generated pages with assemble用 assemble 生成页面的路径
【发布时间】:2013-11-21 11:43:15
【问题描述】:

我正在为grunt-assemble grunt 任务配置苦苦挣扎,看起来像这样:

assemble: {
  options: {
    flatten: false,
    expand: true,

    assets: '',

    layout: 'default.hbs',
    layoutdir: 'templates/layouts',

    partials: ['templates/includes/*.hbs'],
    helpers: ['templates/helpers/*.js'],
    data: ['templates/data/*.{json,yml}']
  },

  dev: {
    src: 'templates/pages/**/*.hbs',
    dest: 'build/'
  }

assemble.io 的项目模板的脚手架如下所示:

templates
├── helpers
├── includes
│   ├── page-footer.hbs
│   ├── page-header.hbs
│   └── scripts.hbs
├── layouts
│   └── default.hbs
└── pages
    ├── en
    │   └── index.hbs
    ├── fr
    │   └── index.hbs
    └── index.hbs

我的愿望是得到类似的东西:

build
├── en
│   └── index.html
├── fr
│   └── index.html
└── index.html

但是我得到了类似的东西:

build
└── templates
    └── pages
        ├── en
        │   └── index.html
        ├── fr
        │   └── index.html
        └── index.html

我确实尝试了一些(实际上很多)组合(使用 flattenexpand 以及 cwd 选项),但我被卡住了。

使用flatten 会导致index.html 文件相互覆盖。

所以我实际上是在 .tmp 目录中进行渲染,然后将文件移动到 build 目录中。 我不喜欢那个解决方案,因为那时page.assets 仍然损坏(它的值将是../../..,对于根index.html)。

【问题讨论】:

    标签: gruntjs assemble grunt-assemble


    【解决方案1】:

    咕噜组装

    (请注意,此信息特指 grunt-assemble 0.4.x,它是用于 assemble 的 grunt 插件,但具有完全不同的 API)

    @doowb 几乎是正确的,尝试将expand: trueext: '.html' 添加到文件配置中:

    assemble: {
      options: {
        flatten: false,
        expand: true,
    
        assets: '',
    
        layout: 'default.hbs',
        layoutdir: 'templates/layouts',
    
        partials: ['templates/includes/*.hbs'],
        helpers: ['templates/helpers/*.js'],
        data: ['templates/data/*.{json,yml}']
      },
    
      dev: {
        files: [
          {expand: true, cwd: 'templates/pages/', src: '**/*.hbs', dest: 'build/', ext: '.html'}
        ]
      }
    }
    

    也可以看看https://github.com/assemble/assemble-contrib-permalinks

    组装 0.7.x

    集合在 assemble 0.7.0 中是一流的,插件也是如此,因此生成相对链接、构建分页和创建自定义永久链接等事情要容易得多。

    如果您使用的是 assemble 0.7.x 及更高版本,assemble-permalinks 是您想要使用的插件。

    【讨论】:

    • 非常感谢!我正在寻找正确的地方,但它与 files 对象或其他可能的语法有点混淆。
    • 如何使用 node assemble @jonschlinkert @doowb 完成这项工作?会不会像... app.pages([path to pages], { [file config]} 或者这只是一个笨拙的东西 atm?
    【解决方案2】:

    您是否尝试将扩展的 files 对象用于具有 cwd 属性的 grunt 目标?

    assemble: {
      options: {
        flatten: false,
        expand: true,
    
        assets: '',
    
        layout: 'default.hbs',
        layoutdir: 'templates/layouts',
    
        partials: ['templates/includes/*.hbs'],
        helpers: ['templates/helpers/*.js'],
        data: ['templates/data/*.{json,yml}']
      },
    
      dev: {
        files: [
          { cwd: 'templates/pages/', src: '**/*.hbs', dest: 'build/' }
        ]
      }
    }
    

    【讨论】:

    • 我确实做到了。出现有关未找到文件的错误,看起来像错误:无法读取“index.hbs”文件(错误代码:ENOENT)。在 Object.util.error (..../node_modules/grunt/lib/grunt/util.js:57:39) 在 Object.file.read (..../node_modules/grunt/lib/grunt/file. js:237:22) 在 buildPage (..../node_modules/assemble/tasks/assemble.js:289:78) 在 ..../node_modules/assemble/tasks/assemble.js:345:23
    猜你喜欢
    • 1970-01-01
    • 2019-02-21
    • 1970-01-01
    • 2022-08-15
    • 2013-08-05
    • 2014-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多