在一个Wintersmith应用程序(node.js静态站点生成器)中,我有一些内容/文章要预先编写。
我只希望在它们的metadata.date已经过去时生成它们,直到生成的日期。
你怎么能和温特史密斯一起这么做?
发布于 2013-09-26 16:59:07
你有几个选择。一个简单而又麻烦的方法是使用文件名模板,并将文件名设置为类似于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-26 16:53:50
当然,您可以继续为此目的更改分页器文件-
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-11-07 20:00:53
另一个恶意的解决方案是有一个子文件夹调用_draft,您可以htaccess保护该文件夹中的所有内容。当您想要推广它时,只需将其复制到正确的位置。
https://stackoverflow.com/questions/19033010
复制相似问题