slashdotdash / jekyll-lunr-js-search

[UNSUPPORTED] Jekyll + lunr.js = static websites with powerful full-text search using JavaScript
MIT License
548 stars 109 forks source link

Adding hook #122

Closed anthonygore closed 7 years ago

anthonygore commented 7 years ago

Since the search and population of the template is async, it's difficult to modify the page any further. I've added a hook which runs after the results are shown. Now you can do something like this:

$('#search-query').lunrSearch({
    indexUrl  : '/lunr/index.json',
    results   : '#search-results',
    template  : '#search-results-template',
    titleMsg  : '<div class="search-results-message"><h3>Search results<h3></div>',
    emptyMsg  : '<div class="search-results-message"><h3>Nothing found!</h3><div><p>Show <a href="/search/?q=">all posts</a>.</p></div></div>',
    onAfterResultShow : function() {
      $().updateShareCounts();
    }
  });
slashdotdash commented 7 years ago

Great, thanks for the pull request @anthonygore.