Skip to content
This repository has been archived by the owner on Sep 18, 2019. It is now read-only.

error on build? #1

Closed
cboettig opened this issue Mar 7, 2013 · 10 comments
Closed

error on build? #1

cboettig opened this issue Mar 7, 2013 · 10 comments

Comments

@cboettig
Copy link

cboettig commented Mar 7, 2013

This looks like a great plugin, thanks for sharing.

Probably missing something simple here, but after following your directions I get the following error on build:

jekyll --server
Configuration from /home/cboettig/Documents/labnotebook/_config.yml
Building site: /home/cboettig/Documents/labnotebook -> /home/cboettig/Documents/labnotebook/_site
Running the search indexer...
/home/cboettig/Documents/labnotebook/_plugins/jekyll_lunr_js_search.rb:24:in `generate': undefined method `each' for nil:NilClass (NoMethodError)
    from /var/lib/gems/1.9.1/gems/jekyll-0.12.1/lib/jekyll/site.rb:190:in `block in generate'
    from /var/lib/gems/1.9.1/gems/jekyll-0.12.1/lib/jekyll/site.rb:189:in `each'
    from /var/lib/gems/1.9.1/gems/jekyll-0.12.1/lib/jekyll/site.rb:189:in `generate'
    from /var/lib/gems/1.9.1/gems/jekyll-0.12.1/lib/jekyll/site.rb:40:in `process'
    from /var/lib/gems/1.9.1/gems/jekyll-0.12.1/bin/jekyll:264:in `<top (required)>'
    from /usr/local/bin/jekyll:23:in `load'
    from /usr/local/bin/jekyll:23:in `<main>'

If you care to have a look, my instance with your search mechanism enabled is on this branch here: https://github.com/cboettig/labnotebook/tree/site-search

(note that on that branch your search method is just implemented on the search.html page, the search in the navbar uses my former local search, adapted from marran)

@slashdotdash
Copy link
Owner

Thanks for giving the plugin a whirl, sorry it didn't actually work!

I'll take a look at the problem tonight. Running it through your actual Jekyll site should make it straightforward to track down and fix.

@cboettig
Copy link
Author

cboettig commented Mar 7, 2013

Thanks!

Also thanks for answering my query on SO about memory, good to know. I'm
wondering if I'll need to replace the search form that appears in my navbar
to keep search on a dedicated separate page. I noticed your Readme says

t also features on-demand loading of the search plugin .js when focusing
into the search field on the homepage http://10consulting.com/. Look at
the browser network requests clicking into the search input.

so perhaps it wouldn't be necessary to do that, since if I understand
correctly that the loading into memory doesn't happen until the user clicks
on the search field?

On Thu, Mar 7, 2013 at 2:26 AM, Ben Smith notifications@github.com wrote:

Thanks for giving the plugin a whirl, sorry it didn't actually work!

I'll take a look at the problem tonight. Running it through your actual
Jekyll site should make it straightforward to track down and fix.


Reply to this email directly or view it on GitHubhttps://github.com//issues/1#issuecomment-14547853
.

Carl Boettiger
UC Santa Cruz
http://www.carlboettiger.info/

@slashdotdash
Copy link
Owner

The on-demand loading isn't included in the plugin at the moment, but here's a gist of the JavaScript that I'm using to achieve this on the homepage of my website.

https://gist.github.com/slashdotdash/a9441baea14228ab84be

Here's the actual focus wireup and on-demand js loading part. It only does this once, regardless of how many times the input field gets focus.

// load the search .js file when the search query input gains focused (once)
var loadOnDemand = function(loaded) {
    focused('search-query', once(function() {
      demand('/js/search.min.js', loaded);
    }));
};

Using this approach both the .js file and index JSON data are not actually requested from the server (or loaded into memory) until the user clicks/focuses on the search input field.

@slashdotdash
Copy link
Owner

Minified version can be included in standard <script>..</script> tags in the html body so there are no external requests.

https://gist.github.com/slashdotdash/a9441baea14228ab84be#file-on-demand-search-min-js

@slashdotdash
Copy link
Owner

Above commit should fix your issue Carl. I've run the plugin on your site, albeit with all others removed, and it generated the search.json index file.

Let me know if you encounter any problems.

@cboettig
Copy link
Author

cboettig commented Mar 9, 2013

Thanks! That definitely fixed the ruby end, I can verify that search.json is being created correctly. The site now builds successfully ..., but I don't seem to be getting the javascript to run on my search.html page. Current attempt here (site-search branch): https://github.com/cboettig/labnotebook/tree/b56794d74f4bf0fee91e355d10096ac2ffd50856

I haven't added the "load on select" script yet,but still probably me doing something stupid with the javascript. Thanks for the help!

@slashdotdash
Copy link
Owner

Had a play around and eventually got it working, couple of things were causing it to be unhappy.

  • Exclude 404 page from search index (ensure _config.yml contains lunr_excludes: [atom.xml, 404.html])
  • You already reference jQuery in the footer of your template. So the search JavaScript snippet and import script reference (<script src="/assets/js/search.min.js" type="text/javascript" charset="utf-8"></script>) need to be after jQuery is included.
  • Also related, use the following minified search.min.js which has jQuery removed https://gist.github.com/slashdotdash/f6be39fcd1ae2615a2b5
  • The search results Mustache template needs to be wrapped in {% raw %} and {% endraw %} tags so that the content is not stripped out by Jekyll

@slashdotdash
Copy link
Owner

Also the Mustache search results template needs to be as follows (some of the Jekyll tags were stripped on the blog post).

{% raw %}

<script id="search-results-template" type="text/mustache"> {{#entries}}

{{#date}}{{displaydate}}{{/date}} {{title}}

{{/entries}} </script>

{% endraw %}

@cboettig
Copy link
Author

thanks. I've followed these changes but still no dice. Does search on the
search.html or 404.html pages work for you if you locally compile my site?

You've already gone above the call of duty I think in replying to my
particular case here, so no worries if you don't have time to look at this
again. not sure what I've missed.

Snapshot of my current build here:
https://github.com/cboettig/labnotebook/tree/b4c5141a6886218e7741173cb0674f54961adb27

The search page looks like a functional match to the one at
http://10consulting.com/search/ so I'm puzzled. I did try moving my
javascript to the header or turning off all other javascript too, but no
luck there either.

On Sun, Mar 10, 2013 at 3:38 AM, Ben Smith notifications@github.com wrote:

Also the Mustache search results template needs to be as follows (some of
the Jekyll tags were stripped on the blog post).

{% raw %}
{{#entries}}

{{#date}}{{displaydate}}{{/date}} {{title}}

{{/entries}}

{% endraw %}


Reply to this email directly or view it on GitHubhttps://github.com//issues/1#issuecomment-14679333
.

Carl Boettiger
UC Santa Cruz
http://www.carlboettiger.info/

@slashdotdash
Copy link
Owner

I'll send send you a pull request with the changes I made to get search working.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants