正在尝试为Docpad网站设置Lunr全文搜索插件.我做错了什么
Trying to set up Lunr full-text search plugin for Docpad site. What am I doing wrong?
我正在使用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插件的存储库README,但我并不总是确定将配置属性放在哪里。但这是我提出的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" ) %>
我还没有抽出时间尝试在网站模板中插入搜索栏,因为基础知识已经突破了。我做错了什么?如有任何帮助,我们将不胜感激。
我从来没有让这部分工作过。我的决定过去和现在都做得很好——我直接修改源代码(我知道,这是一种糟糕的做法,如果你愿意,你也可以派生项目)。因此,在您的项目中,您有node_modules/docpad-plugin-lunr/out/lunrdoc.js
,并且有一个resultsTemplate属性,您可以修改
我从未让Lunr插件工作过,但我认为我已经想出了一个更好、更简单的解决方案。
我最终做的是一个简单的HTML表单,它在DuckDuckGo上对我的网站进行自定义搜索——尽管我相信你可以很容易地调整它来使用你喜欢的任何搜索引擎。
<!--
Here, method="post" hides the query parameters, so the code doesn't
appear in the search results page URL. You can change attribute
`method` to "get" if you want all the parameters to show in the URL
bar when users go to the search page.
-->
<form action="https://duckduckgo.com/" method="post">
<!--
Input elements with type="hidden" won't render on your page, but
they send extra parameters when users submit the form. For
example, this will set DuckDuckGo to show search results for
*your* website.
-->
<input type="hidden" name="sites" value="YOURDOMAIN.URL" />
<!--
DuckDuckGo has a variety of parameters you can set to customize
the look and feel of the search results page. See
<https://duckduckgo.com/params> for a full list.
For example, this will set the page to use DuckDuckGo's
dark theme.
-->
<input type="hidden" name="kae" value="d" />
<!--
label the search bar with, say, a magnifying lens icon, or just
the word "Search." the `for` attribute has to match the `id`
attribute of the input element with type="search" coming up after
this.
-->
<label for="search-bar">
<img src="/PATH/TO/SEARCH/ICON.jpg" alt="Search" />
</label>
<!--
The actual search bar. This sends the user's search terms to
DuckDuckGo. You can also add a `placeholder` attribute here to
show placeholder text until the user starts typing in the search
bar.
-->
<input id="search-bar" type="search" name="q" />
<button id="search-button" type="submit" title="search provided by DuckDuckGo">Go</button>
</form>
相关文章:
- 免费的JQuery表排序插件(带搜索)
- 正在尝试为Docpad网站设置Lunr全文搜索插件.我做错了什么
- 即时搜索jquery插件
- 使用引导表插件,如何在首次加载时设置搜索字符串
- 选择带有空格的jQuery插件搜索
- 谷歌地图 API v3 位置搜索与 jQuery 自动完成插件
- 使用Spotify API插件专辑名称和歌手名称搜索曲目
- jQuery可搜索下拉插件错误
- 带有JSON数据源的jQueryDataTables插件在全局搜索中接受多个POST请求
- 在asp.net表中使用jquery快速搜索插件进行快速搜索
- 数据表上的日期范围选择器插件.可以't排序和搜索
- 如何编写firefox插件来改变右边的搜索栏到我自己的搜索服务
- 如何在HTML表单中添加jstree搜索插件
- 搜索js图像裁剪插件,无需jquery
- Firefox说无法下载搜索插件
- jQuery可搜索下拉插件不工作
- 如何使用表排序插件- jquery搜索表中的项
- 如何在Jquery选择插件中搜索乌尔都语?有没有其他的方法来搜索乌尔都语在选择框
- 可搜索下拉菜单的Jquery插件
- jQuery -在实时搜索插件上使用提交按钮执行搜索