【问题标题】:Wintersmith: Two paginated sectionsWintersmith:两个分页部分
【发布时间】:2015-11-26 14:50:58
【问题描述】:

在我的 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。

我怎样才能做到这两点?

【问题讨论】:

  • 但是,如果我使用预览服务器,它将根据请求构建 index.html blog.html。 wintersmith build 将只产生一个索引,但是(但我需要两个)。

标签: wintersmith


【解决方案1】:

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 原则),但它可能是一个很好的快速修复,因为它似乎没有将分页器插件设置为在多个目录上工作。

【讨论】:

    猜你喜欢
    • 2014-04-18
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 2021-01-18
    • 2017-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多