Simple-Jekyll-Search

Build Status

A JavaScript library to add search functionality to any Jekyll blog.


idea from this blog post


Promotion: check out Pomodoro.cc

Demo

Getting started

  • Place the following code in a file called search.json in the root of your Jekyll blog. This file will be used as a small data source to perform the searches on the client side:
---
---
[
  
    {
      "title"    : "Setting up S/PDIF (optical audio) for RasPlex",
      "category" : "",
      "tags"     : "raspberry pi, hifi",
      "url"      : "/2017/06/17/setting-up-spdif-toslink-for-rasplex.html",
      "date"     : "2017-06-17 18:26:00 +0000"
    } ,
  
    {
      "title"    : "What's in my bag?",
      "category" : "",
      "tags"     : "photos, gear",
      "url"      : "/2017/01/25/what-s-in-my-bag.html",
      "date"     : "2017-01-25 21:39:00 +0000"
    } ,
  
    {
      "title"    : "What does Yarn actually want?",
      "category" : "",
      "tags"     : "javascript",
      "url"      : "/2017/01/25/what-does-yarn-actually-want.html",
      "date"     : "2017-01-25 10:54:33 +0000"
    } ,
  
    {
      "title"    : "Best of 2016",
      "category" : "",
      "tags"     : "music",
      "url"      : "/2016/12/23/best-of-2016.html",
      "date"     : "2016-12-23 18:08:40 +0000"
    } ,
  
    {
      "title"    : "Using the screen multiplexer for hidden shell work",
      "category" : "",
      "tags"     : "shell",
      "url"      : "/2016/12/04/using-the-screen-multiplexer-for-hidden-shell-work.html",
      "date"     : "2016-12-04 16:01:05 +0000"
    } ,
  
    {
      "title"    : "Signing Git commits with GPG",
      "category" : "",
      "tags"     : "git, gpg, security",
      "url"      : "/2016/11/29/signing-git-commits-with-gpg.html",
      "date"     : "2016-11-29 10:04:48 +0000"
    } ,
  
    {
      "title"    : "Manually migrating existing data to ownCloud",
      "category" : "",
      "tags"     : "owncloud, php, shell",
      "url"      : "/2016/11/01/manually-migrating-existing-data-to-owncloud.html",
      "date"     : "2016-11-01 12:17:00 +0000"
    } ,
  
    {
      "title"    : "Better system monitoring with Glances",
      "category" : "",
      "tags"     : "system, devops",
      "url"      : "/2016/10/19/better-system-monitoring-with-glances.html",
      "date"     : "2016-10-19 12:02:00 +0000"
    } ,
  
    {
      "title"    : "The iTunes Styleguide for the true music lover",
      "category" : "",
      "tags"     : "music",
      "url"      : "/2016/09/30/the-itunes-styleguide-for-the-true-music-lover.html",
      "date"     : "2016-09-30 21:11:00 +0000"
    } ,
  
    {
      "title"    : "Planning lunch with a Slackbot on Resin",
      "category" : "",
      "tags"     : "ai, raspberry-pi, javascript",
      "url"      : "/2016/05/16/creating-a-slack-lunchbot-on-resin-io.html",
      "date"     : "2016-05-16 11:54:00 +0000"
    } ,
  
    {
      "title"    : "Continuously Deploying Git to (s)ftp",
      "category" : "",
      "tags"     : "cd, devops, git",
      "url"      : "/2016/01/24/continiously-deployment-for-git-to-s-ftp.html",
      "date"     : "2016-01-24 18:42:00 +0000"
    } ,
  
    {
      "title"    : "5 minute guide to keeping your system updated",
      "category" : "",
      "tags"     : "system",
      "url"      : "/2015/12/15/5-minute-guide-to-keeping-your-system-updated.html",
      "date"     : "2015-12-15 11:45:00 +0000"
    } ,
  
    {
      "title"    : "Plants around the workspace",
      "category" : "",
      "tags"     : "workspace, photos",
      "url"      : "/2015/11/25/plants-around-the-workspace.html",
      "date"     : "2015-11-25 19:19:00 +0000"
    } ,
  
    {
      "title"    : "Workspace",
      "category" : "",
      "tags"     : "workspace, photos",
      "url"      : "/2015/10/23/workspace.html",
      "date"     : "2015-10-23 16:21:00 +0000"
    } ,
  
    {
      "title"    : "Quick and easy development environments with Otto",
      "category" : "",
      "tags"     : "devops, vagrant",
      "url"      : "/2015/10/18/quick-and-easy-development-environements-with-otto.html",
      "date"     : "2015-10-18 22:41:00 +0000"
    } ,
  
    {
      "title"    : "Fixing Belgian eID Viewer on El Capitan",
      "category" : "",
      "tags"     : "macos",
      "url"      : "/2015/10/02/fixing-belgian-eid-viewer-on-el-capitan.html",
      "date"     : "2015-10-02 18:43:00 +0000"
    } ,
  
    {
      "title"    : "Getting location data in Photos for OS X",
      "category" : "",
      "tags"     : "macos, photography",
      "url"      : "/2015/08/10/getting-location-data-in-photos-for-os-x.html",
      "date"     : "2015-08-10 13:59:00 +0000"
    } ,
  
    {
      "title"    : "Installing OS X 10.11 as a VM",
      "category" : "",
      "tags"     : "macos",
      "url"      : "/2015/06/16/installing-el-capitan-in-parallels-vm.html",
      "date"     : "2015-06-16 00:00:00 +0000"
    } ,
  
    {
      "title"    : "Raspberry Pi login with SSH keys",
      "category" : "",
      "tags"     : "raspberry-pi, networking, security",
      "url"      : "/2015/05/07/raspberry-pi-login-with-ssh-keys.html",
      "date"     : "2015-05-07 00:00:00 +0000"
    } ,
  
    {
      "title"    : "Using ext4 on OS X Yosemite, the long but safe way",
      "category" : "",
      "tags"     : "macos, hardware, unix",
      "url"      : "/2015/04/08/using-ext4-on-os-x-yosemite-the-long-but-safe-way.html",
      "date"     : "2015-04-08 00:00:00 +0000"
    } ,
  
    {
      "title"    : "Setup r8188eu with Raspbian the easy way",
      "category" : "",
      "tags"     : "raspberry-pi, networking",
      "url"      : "/2015/04/02/setup-r8188eu-with-raspbian-the-easy-way.html",
      "date"     : "2015-04-02 00:00:00 +0000"
    } ,
  
    {
      "title"    : "The BlueLounge Kickflip is amazing",
      "category" : "",
      "tags"     : "photos, review",
      "url"      : "/2015/03/03/the-bluelounge-kickflip-is-amazing.html",
      "date"     : "2015-03-03 00:00:00 +0000"
    } ,
  
    {
      "title"    : "Supercharging the Raspberry Pi for terminal",
      "category" : "",
      "tags"     : "raspberry-pi, shell, bash",
      "url"      : "/2015/02/23/supercharging-the-raspberry-pi-for-terminal.html",
      "date"     : "2015-02-23 00:00:00 +0000"
    } ,
  
    {
      "title"    : "Bridging Wifi to the Raspberry Pi over Ethernet",
      "category" : "",
      "tags"     : "raspberry-pi, networking",
      "url"      : "/2015/02/16/bridging-wifi-to-the-raspberry-pi-over-ethernet.html",
      "date"     : "2015-02-16 00:00:00 +0000"
    } ,
  
    {
      "title"    : "Creating a package for Atom is dead easy",
      "category" : "",
      "tags"     : "atom",
      "url"      : "/2015/01/06/creating-atom-packages.html",
      "date"     : "2015-01-06 00:00:00 +0000"
    } ,
  
    {
      "title"    : "Using Photoshop with a modular approach",
      "category" : "",
      "tags"     : "photoshop, graphic design",
      "url"      : "/2014/12/22/modular-photoshop.html",
      "date"     : "2014-12-22 00:00:00 +0000"
    } ,
  
    {
      "title"    : "Executable HTTP Server Script",
      "category" : "",
      "tags"     : "networking",
      "url"      : "/2014/12/18/http-python-server.html",
      "date"     : "2014-12-18 00:00:00 +0000"
    } ,
  
    {
      "title"    : "Quick toggle Yosemite's Dark Theme",
      "category" : "",
      "tags"     : "macos",
      "url"      : "/2014/10/21/yosemite-dark-menubar.html",
      "date"     : "2014-10-21 00:00:00 +0000"
    } ,
  
    {
      "title"    : "Playing Facebook video without Flash",
      "category" : "",
      "tags"     : "facebook, flash",
      "url"      : "/2014/10/20/facebook-without-flash.html",
      "date"     : "2014-10-20 00:00:00 +0000"
    } ,
  
    {
      "title"    : "That old 1st Gen Apple TV - Converting it to a local server",
      "category" : "",
      "tags"     : "apple-tv",
      "url"      : "/2014/08/14/that-old-1st-gen-apple-tv-converting-it-to-a-local-server.html",
      "date"     : "2014-08-14 00:00:00 +0000"
    } ,
  
    {
      "title"    : "Bash…Trash!",
      "category" : "",
      "tags"     : "macos, bash",
      "url"      : "/2014/07/07/bash-trash.html",
      "date"     : "2014-07-07 00:00:00 +0000"
    } 
  
]
  • configure the library ( options )

Note that the index generated in search.json does not include the posts’ content since you may not want to load the whole content of your blog in each single page. However, if some of you want to enable full-text search, you can still add the posts’ content to the index, either to the normal search, or on an additional search page with a dedicated second index file. To do this, simply add

"content"  : ""

to search.json after the "date" line to which you must add a comma (,).

Install with bower

bower install simple-jekyll-search

Setup

You need to place the following code within the layout where you want he search to appear.

For example in _layouts/default.html:

<!-- Html Elements for Search -->
<div id="search-container">
<input type="text" id="search-input" placeholder="search...">
<ul id="results-container"></ul>
</div>

<!-- Script pointing to jekyll-search.js -->
<script src="/bower_components/simple-jekyll-search/dest/jekyll-search.js" type="text/javascript"></script>

Options

Customize SimpleJekyllSearch by passing in your configuration options:

SimpleJekyllSearch({
  searchInput: document.getElementById('search-input'),
  resultsContainer: document.getElementById('results-container'),
  json: '/search.json',
})

The above initialization needs to occur after the inclusion of jekyll-search.js.

searchInput (Element) [required]

The input element on which the plugin should listen for keyboard event and trigger the searching and rendering for articles.

resultsContainer (Element) [required]

The container element in which the search results should be rendered in. Typically an <ul>.

json (String|JSON) [required]

You can either pass in an URL to the search.json file, or the results in form of JSON directly, to save one round trip to get the data.

searchResultTemplate

The template of a single rendered search result.

The templating syntax is very simple: You just enclose the properties you want to replace with curly braces.

E.g.

The template

<li><a href="{url}">{title}</a></li>

will render to the following

<li><a href="/jekyll/update/2014/11/01/welcome-to-jekyll.html">Welcome to Jekyll!</a></li>

If the search.json contains this data

[

    {
      "title"    : "Welcome to Jekyll!",
      "category" : "",
      "tags"     : "",
      "url"      : "/jekyll/update/2014/11/01/welcome-to-jekyll.html",
      "date"     : "2014-11-01 21:07:22 +0100"
    }

]

noResultsText

The HTML that will be shown if the query didn’t match anything.

limit

You can limit the number of posts rendered on the page.

fuzzy

Enable fuzzy search to allow less restrictive matching.

##Browser support

Browser support should be about IE6+ with this addEventListener shim

Dev setup

  • npm install the dependencies.

  • gulp watch during development

  • npm test or npm run watch-test to run the unit tests

#License ##MIT licensed Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.