【问题标题】:Why am I getting an error when installing lunr.js search on Jekyll?为什么在 Jekyll 上安装 lunr.js 搜索时出现错误?
【发布时间】:2015-01-31 19:50:24
【问题描述】:

我正在尝试在 jekyll 网站上安装 lunr.js,但出现此错误:

Users/tjohnson/projects/resolve/_plugins/jekyll_lunr_js_search.rb:5:in `require': cannot load such file -- v8 (LoadError)
from /Users/tjohnson/projects/resolve/_plugins/jekyll_lunr_js_search.rb:5:in `<top (required)>'
from /Users/tjohnson/.rvm/gems/ruby-2.0.0-p481/gems/jekyll-2.4.0/lib/jekyll/plugin_manager.rb:58:in `require'
from /Users/tjohnson/.rvm/gems/ruby-2.0.0-p481/gems/jekyll-2.4.0/lib/jekyll/plugin_manager.rb:58:in `block (2 levels) in require_plugin_files'
from /Users/tjohnson/.rvm/gems/ruby-2.0.0-p481/gems/jekyll-2.4.0/lib/jekyll/plugin_manager.rb:57:in `each'
from /Users/tjohnson/.rvm/gems/ruby-2.0.0-p481/gems/jekyll-2.4.0/lib/jekyll/plugin_manager.rb:57:in `block in require_plugin_files'
from /Users/tjohnson/.rvm/gems/ruby-2.0.0-p481/gems/jekyll-2.4.0/lib/jekyll/plugin_manager.rb:56:in `each'
from /Users/tjohnson/.rvm/gems/ruby-2.0.0-p481/gems/jekyll-2.4.0/lib/jekyll/plugin_manager.rb:56:in `require_plugin_files'
from /Users/tjohnson/.rvm/gems/ruby-2.0.0-p481/gems/jekyll-2.4.0/lib/jekyll/plugin_manager.rb:18:in `conscientious_require'
from /Users/tjohnson/.rvm/gems/ruby-2.0.0-p481/gems/jekyll-2.4.0/lib/jekyll/site.rb:74:in `setup'
from /Users/tjohnson/.rvm/gems/ruby-2.0.0-p481/gems/jekyll-2.4.0/lib/jekyll/site.rb:36:in `initialize'
from /Users/tjohnson/.rvm/gems/ruby-2.0.0-p481/gems/jekyll-2.4.0/lib/jekyll/commands/build.rb:28:in `new'
from /Users/tjohnson/.rvm/gems/ruby-2.0.0-p481/gems/jekyll-2.4.0/lib/jekyll/commands/build.rb:28:in `process'
from /Users/tjohnson/.rvm/gems/ruby-2.0.0-p481/gems/jekyll-2.4.0/lib/jekyll/commands/serve.rb:25:in `block (2 levels) in init_with_program'
from /Users/tjohnson/.rvm/gems/ruby-2.0.0-p481/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in `call'
from /Users/tjohnson/.rvm/gems/ruby-2.0.0-p481/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in `block in execute'
from /Users/tjohnson/.rvm/gems/ruby-2.0.0-p481/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in `each'
from /Users/tjohnson/.rvm/gems/ruby-2.0.0-p481/gems/mercenary-0.3.5/lib/mercenary/command.rb:220:in `execute'
from /Users/tjohnson/.rvm/gems/ruby-2.0.0-p481/gems/mercenary-0.3.5/lib/mercenary/program.rb:42:in `go'
from /Users/tjohnson/.rvm/gems/ruby-2.0.0-p481/gems/mercenary-0.3.5/lib/mercenary.rb:19:in `program'
from /Users/tjohnson/.rvm/gems/ruby-2.0.0-p481/gems/jekyll-2.4.0/bin/jekyll:18:in `<top (required)>'
from /Users/tjohnson/.rvm/gems/ruby-2.0.0-p481/bin/jekyll:23:in `load'
from /Users/tjohnson/.rvm/gems/ruby-2.0.0-p481/bin/jekyll:23:in `<main>'
from /Users/tjohnson/.rvm/gems/ruby-2.0.0-p481/bin/ruby_executable_hooks:15:in `eval'
from /Users/tjohnson/.rvm/gems/ruby-2.0.0-p481/bin/ruby_executable_hooks:15:in `<main>'

我正在尝试按照https://github.com/slashdotdash/jekyll-lunr-js-search 上的说明进行操作,但我对 Jekyll 有点陌生,所以我可能无法理解所有内容。有两种安装方法:使用 ruby​​gem 或直接下载预构建的插件文件。我选择了后者。以下是我采取的步骤:

  1. 将 repo 克隆到我的本地计算机。
  2. 将 jekyll_lunr_js_search.rb 和 jekyll_lunr_js_search 文件夹移到我的 _plugins 目录中。
  3. 已下载缩小的 search.min.js 文件(其中包含许多其他 js)并将其添加到我的 javascript 目录中。
  4. 已将 jquery.lunr.search.js 添加到我的 javascript 目录中。
  5. 在我的 default.html 文件中添加了以下引用:
<script src="{{ "/javascripts/search.min.js" | prepend:site.baseurl }}">
    </script>
    <script src="{{ "/javascripts/jquery.lunr.search.js" | prepend:site.baseurl}}"></script>
  1. 也将此脚本添加到我的 default.html(通过包含):
 <script type="text/javascript">
    $(function() {
    $('#search-query').lunrSearch({
         indexUrl: '/js/index.json',   // Url for the .json file containing search index data
          results : '#search-results',  // selector for containing search results element
          entries : '.entries',         // selector for search entries containing element (contained within results above)
          template: '#search-results-template'  // selector for Mustache.js template
        });
      });
    </script>
  1. 将此搜索表单添加到页面:
 <div id="search">
      <form action="/search" method="get">
        <input type="text" id="search-query" name="q" placeholder="Search" autocomplete="off">
      </form>
        </div>

这个结果容器就在同一页面上的表单下方:

 <section id="search-results" style="display: none;">
      <p>Search results</p>
      <div class="entries">
      </div>
    </section>

下面这个小胡子模板:

 {% raw %}
    <script id="search-results-template" type="text/mustache">
      {{#entries}}
        <article>
          <h3>
            {{#date}}<small><time datetime="{{pubdate}}" pubdate>{{displaydate}}</time></small>{{/date}}
            <a href="{{url}}">{{title}}</a>
          </h3>
        </article>
      {{/entries}}
    </script>
    {% endraw %}

现在,当我构建我的 jekyll 站点时,我收到了前面列出的错误。 (没有插件我不会得到这个错误。)有什么想法吗?我真的需要在我的网站上提供搜索功能,而这个似乎是最好的。

【问题讨论】:

  • 我也面临同样的问题,尝试按照许多搜索项目中的建议使用 gem install libv8,但这也不起作用......

标签: jekyll jekyll-extensions


【解决方案1】:

先尝试安装libv8 Ruby gem。

gem install libv8 -v '3.16.14.7'

gem install libv8 -v '3.16.14.7' -- --with-system-v8

然后安装最新版本的jekyll_lunr_js_search gem。

gem install jekyll-lunr-js-search

最后,在 Jekyll 站点的 _config.yml 配置文件中包含对插件 gem 的引用。

gems: ['jekyll-lunr-js-search']

【讨论】:

    猜你喜欢
    • 2021-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-02
    • 1970-01-01
    • 1970-01-01
    • 2016-08-12
    • 1970-01-01
    相关资源
    最近更新 更多