A JavaScript library to add search functionality to any Jekyll blog.
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.
npm install simple-jekyll-search
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 %}
]
SimpleJekyllSearch needs two DOM
elements to work:
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:
<!-- HTML elements for search -->
<input type="text" id="search-input" placeholder="Search blog posts..">
<ul id="results-container"></ul>
<!-- or without installing anything -->
<script src="https://unpkg.com/simple-jekyll-search@latest/dest/simple-jekyll-search.min.js"></script>
Customize SimpleJekyllSearch by passing in your configuration options:
var sjs = SimpleJekyllSearch({
searchInput: document.getElementById('search-input'),
resultsContainer: document.getElementById('results-container'),
json: '/search.json'
})
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')
Here is a list of the available options, usage questions, troubleshooting & guides.
The input element on which the plugin should listen for keyboard event and trigger the searching and rendering for articles.
The container element in which the search results should be rendered in. Typically a <ul>
.
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.
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
var sjs = SimpleJekyllSearch({
searchInput: document.getElementById('search-input'),
resultsContainer: document.getElementById('results-container'),
json: '/search.json',
searchResultTemplate: '<li><a href="{{ site.url }}{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"
}
]
A function that will be called whenever a match in the template is found.
It gets passed the current property name, property value, and the template.
If the function returns a non-undefined value, it gets replaced in the template.
This can be potentially useful for manipulating URLs etc.
Example:
SimpleJekyllSearch({
...
templateMiddleware: function(prop, value, template) {
if (prop === 'bar') {
return value.replace(/^\//, '')
}
}
...
})
See the tests for an in-depth code example
A function that will be used to sort the filtered results.
It can be used for example to group the sections together.
Example:
SimpleJekyllSearch({
...
sortMiddleware: function(a, b) {
var astr = String(a.section) + "-" + String(a.caption);
var bstr = String(b.section) + "-" + String(b.caption);
return astr.localeCompare(bstr)
}
...
})
The HTML that will be shown if the query didn't match anything.
You can limit the number of posts rendered on the page.
Enable fuzzy search to allow less restrictive matching.
Pass in a list of terms you want to exclude (terms will be matched against a regex, so URLs, words are allowed).
A function called once the data has been loaded.
Limit how many times the search function can be executed over the given time window. This is especially useful to improve the user experience when searching over a large dataset (either with rare terms or because the number of posts to display is large). If no debounceTime
(milliseconds) is provided a search will be triggered on each keystroke.
remove_chars
as a filter.For example: in search.json, replace
"content": "{{ page.content | strip_html | strip_newlines }}"
with
"content": "{{ page.content | strip_html | strip_newlines | remove_chars | escape }}"
If this doesn't work when using Github pages you can try jsonify
to make sure the content is json compatible:
"content": {{ page.content | jsonify }}
Note: you don't need to use quotes "
in this since jsonify
automatically inserts them.
Replace search.json
with the following code:
---
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 }}",
"content" : "{{ post.content | strip_html | strip_newlines }}"
} {% unless forloop.last %},{% endunless %}
{% endfor %}
,
{% for page in site.pages %}
{
{% if page.title != nil %}
"title" : "{{ page.title | escape }}",
"category" : "{{ page.category }}",
"tags" : "{{ page.tags | join: ', ' }}",
"url" : "{{ site.baseurl }}{{ page.url }}",
"date" : "{{ page.date }}",
"content" : "{{ page.content | strip_html | strip_newlines }}"
{% endif %}
} {% unless forloop.last %},{% endunless %}
{% endfor %}
]
npm install
npm test
cd example; jekyll serve
# in another tab
npm run cypress -- run
Thanks to all contributors over the years! You are the best :)
@daviddarnes@XhmikosR@PeterDaveHello@mikeybeck@egladman@midzer@eduardoboucas@kremalicious@tibotiberand many others!
一、安装 Simple-Jekyll-Search npm 安装(需要 Node.js 环境) npm install simple-jekyll-search 复制代码 或者 bower 安装 bower install --save simple-jekyll-search 复制代码 二、在 Jekyll 博客根目录中新建 search.json --- layout: null --- [
Simple Texture Jekyll Theme Simple Texture is a gem-based responsive simple texture styled Jekyll theme for Jekyll 3.3 or above,which can also be forked as a boilerplate for older versions of Jekyll.
本软件可以帮助Rails项目快速实现搜索/过滤页面。具体使用,请参照软件主页里的说明。
Jekyll 是一个简单的免费的Blog生成工具,类似WordPress。但是和WordPress又有很大的不同,原因是jekyll只是一个生成静态网页的工具,不需要数据库支持。但是可以配合第三方服务,例如discuz。最关键的是jekyll可以免费部署在Github上,而且可以绑定自己的域名。 快速安装指令: gem install jekylljekyll new my-awesome-sit
Jekyll Tipue Search Full-text search in Jekyll with Tipue Search. No plugin necessary. Fully compatible with Github Pages. The search index at tipuesearch/tipuesearch_content.js is generated with Liqu
To install Tengine, just follow these three steps: $ ./configure $ make # make install By default, it will be installed to /usr/local/nginx. You can use the '--prefix' option to specify the root dire
插入 // 单条插入 User user=new User(); // 省略entity属性赋值... ... elasticsearchTemplate.save(user); // 批量插入 LinkedList<User> users= new LinkedList<User>(); // 省略entity属性赋值... ... elasticsearchTemplate.save(user