我正在使用 Docpad 构建一个静态网站。我正在尝试为全文站点搜索设置Lunr插件,但我不断收到此错误:
$ docpad run
info: Welcome to DocPad v6.78.1 (local installation: /PATH/TO/WEBSITE/REPOSITORY/node_modules/docpad)
info: Plugins: cleanurls, eco, livereload, lunr, marked, moment, partials, rss, sitemap, stylus
info: Environment: development
info: DocPad listening to http://127.0.0.1:9778/ on directory /PATH/TO/WEBSITE/REPOSITORY/out
info: LiveReload listening to new socket on channel /docpad-livereload
ReferenceError: partial is not defined
at Object.eval (<anonymous>:41:18)
at Object.eval (<anonymous>:51:8)
at eval (<anonymous>:53:6)
at Function.eco.render (/PATH/TO/WEBSITE/REPOSITORY/node_modules/docpad-plugin-eco/node_modules/eco/lib/index.js:26:25)
at EcoPlugin.render (/PATH/TO/WEBSITE/REPOSITORY/node_modules/docpad-plugin-eco/out/eco.plugin.js:23:32)
at ambi (/PATH/TO/WEBSITE/REPOSITORY/node_modules/docpad/node_modules/ambi/out/lib/ambi.js:57:27)
at Task.<anonymous> (/PATH/TO/WEBSITE/REPOSITORY/node_modules/docpad/node_modules/event-emitter-grouped/out/lib/event-emitter-grouped.js:45:23)
at ambi (/PATH/TO/WEBSITE/REPOSITORY/node_modules/docpad/node_modules/ambi/out/lib/ambi.js:55:18)
at fireMethod (/PATH/TO/WEBSITE/REPOSITORY/node_modules/docpad/node_modules/taskgroup/out/lib/taskgroup.js:397:23)
at b (domain.js:183:18)
at Domain.run (domain.js:123:23)
at Task.fire (/PATH/TO/WEBSITE/REPOSITORY/node_modules/docpad/node_modules/taskgroup/out/lib/taskgroup.js:435:27)
at Object._onImmediate (/PATH/TO/WEBSITE/REPOSITORY/node_modules/docpad/node_modules/taskgroup/out/lib/taskgroup.js:452:26)
at processImmediate [as _immediateCallback] (timers.js:354:15)
info: Generating...
error: The action completed successfully
error: Something went wrong while rendering: /PATH/TO/WEBSITE/REPOSITORY/src/render/search.html.eco
The error follows:
ReferenceError: partial is not defined
at Object.eval (<anonymous>:41:18)
at Object.eval (<anonymous>:51:8)
at eval (<anonymous>:53:6)
at Function.eco.render (/PATH/TO/WEBSITE/REPOSITORY/node_modules/docpad-plugin-eco/node_modules/eco/lib/index.js:26:25)
at EcoPlugin.render (/PATH/TO/WEBSITE/REPOSITORY/node_modules/docpad-plugin-eco/out/eco.plugin.js:23:32)
at ambi (/PATH/TO/WEBSITE/REPOSITORY/node_modules/docpad/node_modules/ambi/out/lib/ambi.js:57:27)
at Task.<anonymous> (/PATH/TO/WEBSITE/REPOSITORY/node_modules/docpad/node_modules/event-emitter-grouped/out/lib/event-emitter-grouped.js:45:23)
at ambi (/PATH/TO/WEBSITE/REPOSITORY/node_modules/docpad/node_modules/ambi/out/lib/ambi.js:55:18)
at fireMethod (/PATH/TO/WEBSITE/REPOSITORY/node_modules/docpad/node_modules/taskgroup/out/lib/taskgroup.js:397:23)
at b (domain.js:183:18)
at Domain.run (domain.js:123:23)
at Task.fire (/PATH/TO/WEBSITE/REPOSITORY/node_modules/docpad/node_modules/taskgroup/out/lib/taskgroup.js:435:27)
at Object._onImmediate (/PATH/TO/WEBSITE/REPOSITORY/node_modules/docpad/node_modules/taskgroup/out/lib/taskgroup.js:452:26)
at processImmediate [as _immediateCallback] (timers.js:354:15)
我阅读了 Lunr 插件的存储库自述文件,但我并不总是确定将配置属性放在哪里。但这是docpad.coffee
我想出的属性。
plugins:
lunr:
indexes:
myIndex:
collection: [ "story", "meta" ]
resultsTemplate: "src/partials/search-excerpt.html.eco"
...并且搜索结果部分在src/partials/search-excerpt.html.eco
<div>
<a href="<%= post.url %>"><%= post.title %></a>
<span>posted on <%= post.date %></span>
</div>
...和搜索结果页面src/render/search.html.eco
---
title: "search results"
---
<%- partial( "header" ) %>
<%- @getLunrSearchPage( "myIndex" ) %>
<%- partial( "footer" ) %>
我还没有尝试在网站模板中插入搜索栏,因为基础已经被打破了。我究竟做错了什么?任何帮助将不胜感激。