< Back

Add instant search to your blog or documentation using our Jekyll plugin

Our goal at Algolia is to provide the fastest and the most relevant search experience everywhere around the world. In order to reach this scale, making the life of developers easier had to be one of our founding values. That’s why you can find clients for our API for many languages and frameworks.

Today we are proud to announce the new born in our family of integrations: the Jekyll plugin.

What is Jekyll

Jekyll is a static website generator. You write your content as markdown files, create a few layout templates and it generates the whole HTML website for you. You can then easily deploy it on any web server as it does not need any backend language or database to operate.

Jekyll itself is written in Ruby and is mostly used for blogs or documentation websites. GitHub actually provides a feature called GitHub pages that will automatically build and host a Jekyll website for you if you push it to a branch named gh-pages.

How to use the plugin

As a Jekyll website is only static HTML files, it also means that you cannot have any search capabilities. Or at least you couldn’t until now. With Algolia’s plugin, you now have access to the jekyll algolia push command. It will scan your Jekyll website and push every paragraph of text as a new record to an Algolia index so that you can search it from your website.

Screencast of the search in action

You can see it in action here.

 

This fully tested plugin is available from rubygems and you can easily install it by adding just one line to your Gemfile. Once installed, you only need to edit your _config.yml to add your credentials. All information regarding installation and configuration are available in the readme.

Algolia Jekyll Plugin Badges

How it works

The plugin looks at the HTML files generated by the jekyll build command and extracts every <p> paragraphs of text from them. It then adds a bit of metadata context to each of them and pushes them to your index.

By reading the final HTML pages that are generated, we do not rely on any specific markdown parser and you can even use any custom plugin you’d like.

For each extracted paragraph, we index its raw HTML value as well as its sanitized text. We also include the page url, the full hierarchy of headings (h1 to h6) where the paragraph was found and a few other informations (like a unique CSS selector for the <p> as well as its closest parent heading).

All this information will let you display nice search results and even point the user to the exact matched <p> in the results page. By default, results are grouped by urls, meaning that only the most relevant paragraph of each page will be returned, but this can be changed from the settings (as we’ll see in the next section).

Note that by itself, the plugin only imports your data to your index. For rendering the results, you can follow our tutorials or use our forked version of the popular Hyde theme.

Advanced usage

The default settings are perfectly tuned for a blog, but if you have a different kind of content, you might want to tweak the plugin configuration to fit your needs.

Fortunately, the plugin is highly configurable. First of all, if you want to index more than just <p> paragraphs (maybe you would like headings and block quotes as well), you can define your own CSS selectors.

Next, all the Algolia index settings are overridable directly from the _config.yml file, allowing you to group results based on another attribute, add snippeting to your fields or define your own custom ranking rules.

Finally, we also provide custom hooks that let you write custom code to add your own attributes to your records or add/remove records right before pushing them.

Our goal is to give you as much freedom as possible when using this plugin. We can’t wait to see what you’re going to build with it.

  • http://www.sachagreif.com/ Sacha Greif

    Very cool! Now we just need the same thing for Middleman 🙂

    • http://www.pixelastic.com/ Tim Carry

      Hey, that’s an idea, actually. Do you have an example of where you’re using Middleman?

      • elofjohnson

        I’d be interested in Middleman too! if you want an example of usage in the wild check out http://keen.io/docs

    • Lukyvj

      @pixelastic:disqus @elofjohnson:disqus It’s in the pipe now https://github.com/middleman/middleman/issues/1909

      • https://jay.holtslander.ca/ Jay Holtslander

        Plans for MkDocs? 🙂

  • http://sarahetben.fr/ Sarah & Ben

    Hi, we are considering adding full-text search to our blog sarahetben.fr. Algolia clearly offers a superior user-experience. Are you interested in serving smaller blogs on a free plan ? We are going to try https://github.com/slashdotdash/jekyll-lunr-js-search see how it works.

    • http://www.algolia.com/ Julien Lemoine

      Sure, we have a free plan called hacker plan with 1k records and 50k operations per month. It should be enough for a small blog. Feel free to contact us if you have any question

      • http://sarahetben.fr/ Sarah & Ben

        Thanks for the offer 🙂
        For now we will keep lunr even though it is terrible : (i) search is bad (tokenization, relevance…) (ii) I had to adjust parameters in its code after it started throwing errors at me – just locating the source files is a pain with ruby’s `gem install`. I feel to lazy to change at the moment.
        Other readers, save yourself troubles 🙂