Simple-Jekyll-Search

by christian-fei

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

1.0K Stars 169 Forks Last release: about 5 years ago (1.0.8) MIT License 355 Commits 42 Releases

Available items

1 Support Hour

Developer services
$50.00

Support

Troubleshooting

Simple-Jekyll-Search

Build Status dependencies Status devDependencies Status xscode

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

Use case

You have a blog, built with Jekyll, and want a lightweight search functionality on your blog, purely client-side?

No server configurations or databases to maintain.

Just 5 minutes to have a fully working searchable blog.

Get paid support on xscode


Wiki

Check out the wiki for all available options and help for troubleshooting

Installation

npm

npm install simple-jekyll-search

Getting started

Create
search.json

Place the following code in a file called

search.json
in the root of your Jekyll blog. (You can also get a copy from here)

This file will be used as a small data source to perform the searches on the client side:

---
layout: none
---
[
  {% for post in site.posts %}
    {
      "title"    : "{{ post.title | escape }}",
      "category" : "{{ post.category }}",
      "tags"     : "{{ post.tags | join: ', ' }}",
      "url"      : "{{ site.baseurl }}{{ post.url }}",
      "date"     : "{{ post.date }}"
    } {% unless forloop.last %},{% endunless %}
  {% endfor %}
]

Preparing the plugin

Add DOM elements

SimpleJekyllSearch needs two

DOM
elements to work:
  • a search input field
  • a result container to display the results

Give me the code

Here is the code you can use with the default configuration:

You need to place the following code within the layout where you want the search to appear. (See the configuration section below to customize it)

For example in _layouts/default.html:

    Usage

    Customize SimpleJekyllSearch by passing in your configuration options:

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

    returns { search }

    A new instance of SimpleJekyllSearch returns an object, with the only property

    search
    .

    search
    is a function used to simulate a user input and display the matching results. 

    E.g.:

    var sjs = SimpleJekyllSearch({ ...options })
    sjs.search('Hello')
    

    💡 it can be used to filter posts by tags or categories!

    Options

    Check out the wiki for the options!

    Development

    • npm install
    • npm test

    Acceptance tests

    cd example; jekyll serve
    
    

    in another tab

    npm run cypress -- run

    Contributors

    Thanks to all contributors over the years! You are the best :)

    @daviddarnes @XhmikosR @PeterDaveHello @mikeybeck @egladman @midzer @eduardoboucas @kremalicious @tibotiber and many others!

    Stargazers over time

    Stargazers over time

    We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.