3

在 Wintersmith 应用程序(node.js 静态站点生成器)中,我有几篇我想预先编写的内容/文章。

我只希望在它们的 metadata.date 是过去的生成日期时生成它们。

你怎么能用 Wintersmith 做到这一点?

4

4 回答 4

2

当然,您可以继续为此目的更改分页器文件 -

getArticles = (contents) ->
    # helper that returns a list of articles found in *contents*
    # note that each article is assumed to have its own directory in the articles directory
    articles = contents[options.articles]._.directories.map (item) -> item.index
    #Add the following lines of code 
    articles = articles.filter (article) -> article.metadata.date < new Date
    articles.sort (a, b) -> b.date - a.date
    return articles
于 2013-09-26T16:53:50.163 回答
2

你有几个选择。一个简单但很老套的方法是使用文件名模板并将文件名设置为类似draft.html并在某些 htaccess 文件中忽略它。

在元数据中:filename: "{{ (page.date>Date.now()) ? 'draft' : 'index' }}.html"

另一种选择是创建一个根据您的条件填充树的生成器,例如查看https://github.com/jnordberg/wintersmith/blob/master/examples/blog/plugins/paginator.coffee 。

或者您可以子类化 MarkdownPage 插件并使用您自己的自定义添加重新注册它,也许添加一个draft属性和一个签入getView以将其发送到none如果草稿为真。

class DraftyPage extends MarkdownPage

  isDraft: -> @date > Date.now()

  getView: ->
    return 'none' if @isDraft()
    return super()

env.registerContentPlugin 'pages', '**/*.*(markdown|mkd|md)', DraftyPage

见: https ://github.com/jnordberg/wintersmith/blob/master/src/plugins/page.coffee https://github.com/jnordberg/wintersmith/blob/master/src/plugins/markdown.coffee

于 2013-09-26T16:59:07.343 回答
1

另一个骇人听闻的解决方案是创建一个名为 _draft 的子文件夹,您可以通过 htaccess 保护该文件夹中的所有内容。当您想推广它时,只需将其复制到正确的位置即可。

于 2013-11-07T20:00:53.567 回答
0

不是问题的确切答案,而是解决类似的问题。我希望能够在文章上设置一个草稿变量。解决方案类似于@Tushar:

getArticles = (contents) ->
    # helper that returns a list of articles found in *contents*
    # note that each article is assumed to have its own directory in the articles directory
    articles = contents[options.articles]._.directories.map (item) -> item.index
    # Filter draft articles
    articles = articles.filter (article) -> typeof article.metadata.draft == 'undefined' or article.metadata.draft == false
    articles.sort (a, b) -> b.date - a.date
    return articles
于 2014-01-05T21:54:46.437 回答