Giter Site home page Giter Site logo

Comments (10)

slashdotdash avatar slashdotdash commented on August 22, 2024

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.

from jekyll-lunr-js-search.

cboettig avatar cboettig commented on August 22, 2024

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 [email protected] 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/

from jekyll-lunr-js-search.

slashdotdash avatar slashdotdash commented on August 22, 2024

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.

from jekyll-lunr-js-search.

slashdotdash avatar slashdotdash commented on August 22, 2024

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

from jekyll-lunr-js-search.

slashdotdash avatar slashdotdash commented on August 22, 2024

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.

from jekyll-lunr-js-search.

cboettig avatar cboettig commented on August 22, 2024

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!

from jekyll-lunr-js-search.

slashdotdash avatar slashdotdash commented on August 22, 2024

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

from jekyll-lunr-js-search.

slashdotdash avatar slashdotdash commented on August 22, 2024

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 %}

from jekyll-lunr-js-search.

cboettig avatar cboettig commented on August 22, 2024

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 [email protected] 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/

from jekyll-lunr-js-search.

slashdotdash avatar slashdotdash commented on August 22, 2024

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

from jekyll-lunr-js-search.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.