0

在我的 Wintersmith 构建的站点中,我想要:

  • index.html 包含新闻提要
  • 包含博客索引的 blog.html

我将 paginator.coffee 复制到 newspaginator.coffee 中,对其进行了调整以返回“新闻”而不是“文章”,并进行了一些其他调整,它工作正常。

然后我尝试重新添加原始分页器,并在 config.json 中使用一些参数:

  "plugins": [
    "./plugins/newspaginator.coffee",
    "./plugins/paginator.coffee"
  ],
  "newspaginator": {
    "articles": "news",
    "perPage": 10
  },
  "paginator": {
    "articles": "articles",
    "template": "blog.jade",
    "first": "blog.html",
    "filename": "blogpage/%d/index.html",
    "perPage": 3
  }

现在:我只获得第二个插件的 HTML 页面。如上所述,我得到 blog.html 但没有 index.html。如果我颠倒这两个插件的顺序,我会得到 index.html 但没有 blog.html。

我怎样才能做到这两点?

4

1 回答 1

0

paginator.coffee 设置的一些 Wintersmith 属性需要在您的“调整”中考虑,否则一个插件将覆盖另一个插件的设置。以下是我注意到的:

options = env.config.paginator or {}
...
env.helpers.getArticles = getArticles
...
env.registerGenerator 'paginator', (contents, callback) ->

以 env.helpers.getArticles 为例。在您的模板中的某处,您将调用类似 env.helpers.getArticles(contents) 的内容。这将是第二个调用插件的方法,因为第二个插件覆盖了第一个设置的值。

您应该能够通过更改这三行来使其工作。这仍然是一个 hacky 解决方案,因为您正在复制代码(DRY 原则)但它可能是一个很好的快速修复,因为它似乎没有将分页器插件设置为在多个目录上工作。

于 2015-09-09T16:43:29.690 回答