2015-01-31 100 views
1

我試圖在哲基爾現場安裝lunr.js,我得到這個錯誤:爲什麼在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的指示,但我有點新的化身,所以我可能不理解一切。有兩種方法來安裝它:使用rubygem或直接下載預建的插件文件。我選擇了後者。這裏是我採取的步驟:

  1. 克隆回購到我的本地機器。
  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> 
  • 將此添加腳本到我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> 
    
  • 添加這一搜索表單的PAG E:
  • <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網站時,我收到了前面列出的錯誤。 (沒有插件,我不會得到這個錯誤。)任何想法?我真的需要在我的網站上有一個搜索功能,而這個似乎是最好的。

    +0

    我也面臨同樣的問題,嘗試使用許多搜索項目中建議使用gem install libv8,但那也行不通... – 2015-09-12 12:39:13

    回答

    0

    嘗試先安裝libv8 Ruby寶石。

    gem install libv8 -v '3.16.14.7' 
    

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

    然後安裝最新版本的jekyll_lunr_js_search寶石。

    gem install jekyll-lunr-js-search 
    

    最後,在您的哲基爾網站的_config.yml配置文件的插件寶石的參考。

    gems: ['jekyll-lunr-js-search'] 
    
    相關問題