0

我正在使用 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" ) %>

我还没有尝试在网站模板中插入搜索栏,因为基础已经被打破了。我究竟做错了什么?任何帮助将不胜感激。

4

2 回答 2

0

我从来没有让这个工作正常 - 部分。我的决定是并且效果很好 - 我正在直接修改源(我知道,不好的做法,如果你愿意,你也可以分叉项目)。所以在你的项目中,你有node_modules/docpad-plugin-lunr/out/lunrdoc.js一个 resultsTemplate 属性,你可以修改

于 2015-04-03T07:19:50.083 回答
0

我从来没有让 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>
于 2015-04-05T02:42:18.160 回答