【问题标题】:How to create DocPad plugin?如何创建 DocPad 插件?
【发布时间】:2013-08-06 15:53:17
【问题描述】:

我从 here 开始执行所有步骤:

1) 使用以下代码创建了简单的插件 /plugins/myplugin/myplugin.plugin.coffee:

module.exports = (BasePlugin) ->
  class MyPlugin extends BasePlugin
    name: 'myplugin'
    renderBefore: ({templateData}) ->
      templateData.foo = 'bar'

2) /plugins/myplugin/package.json

{
  "name": "myplugin",
  "version": "2.0.0",
  "main": "./src/myplugin.plugin.coffee"
}

3) /src/documents/index.html.eco

<p><%= @foo %></p>

但插件不起作用。它不在 DocPad 的日志中 info: Plugins: eco 并抛出错误 ReferenceError: foo is not defined

我错过了什么?

【问题讨论】:

  • 我发现了一个问题。每个 DocPad 插件必须在 package.json 中有 "keywords": {"docpad-plugin"} 属性,否则 docpad 会忽略它。

标签: node.js templates plugins content-management-system docpad


【解决方案1】:

您有 /plugins/myplugin/myplugin.plugin.coffee,然后使用 "main": "./src/myplugin.plugin.coffee" 引用它 - 它期望插件文件位于 src 目录中,如下所示:/plugins/myplugin/src/myplugin.plugin.coffee - 您需要更正其中一个。

如果您可以将我链接到文档混淆的地方,我会很乐意修复它。

DocPad 还要求插件在其 package.json 文件中包含以下内容:

"keywords": ["docpad-plugin"]

【讨论】:

  • 我只是不知道"keywords": ["docpad-plugin"],这就是原因。 myplugin.plugin.coffee 在 src/
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-11
  • 2012-03-18
  • 1970-01-01
  • 1970-01-01
  • 2012-09-25
  • 2019-12-22
相关资源
最近更新 更多