├── .github └── workflows │ └── main.yml ├── .gitignore ├── CYPRESS.md ├── LICENSE.md ├── README.md ├── WIKI.md ├── cypress.json ├── cypress ├── fixtures │ ├── example.json │ ├── profile.json │ └── users.json ├── integration │ └── simple-jekyll-search.js ├── plugins │ └── index.js └── support │ ├── commands.js │ └── index.js ├── dest ├── simple-jekyll-search.js └── simple-jekyll-search.min.js ├── example ├── Gemfile ├── _includes │ ├── footer.html │ ├── head.html │ └── header.html ├── _layouts │ ├── default.html │ ├── page.html │ └── post.html ├── _plugins │ ├── simple_search_filter.rb │ └── simple_search_filter_cn.rb ├── _posts │ ├── 2014-11-01-welcome-to-jekyll.markdown │ └── 2014-11-02-test.markdown ├── _sass │ ├── _base.scss │ ├── _layout.scss │ └── _syntax-highlighting.scss ├── about.md ├── css │ └── main.scss ├── index.html ├── js │ ├── simple-jekyll-search.js │ └── simple-jekyll-search.min.js └── search.json ├── index.html ├── package-lock.json ├── package.json ├── scripts └── stamp.js ├── src ├── JSONLoader.js ├── OptionsValidator.js ├── Repository.js ├── SearchStrategies │ ├── FuzzySearchStrategy.js │ └── LiteralSearchStrategy.js ├── Templater.js ├── index.js └── utils.js ├── tests ├── OptionsValidator.test.js ├── Repository.test.js ├── SearchStrategies │ ├── FuzzySearchStrategy.test.js │ └── LiteralSearchStrategy.test.js ├── Templater.test.js └── utils.test.js └── xscode.png /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Simple-Jekyll-Search 2 | on: [push] 3 | jobs: 4 | build_deploy: 5 | runs-on: ubuntu-18.04 6 | steps: 7 | - uses: actions/checkout@master 8 | with: 9 | ref: refs/heads/master 10 | - name: install 11 | run: | 12 | npm install 13 | - name: test 14 | run: | 15 | npm t 16 | # - name: start server for uat 17 | # run: | 18 | # npx http-server example/_site -p 4000 19 | # - name: uat 20 | # uses: cypress-io/github-action@v2 21 | # with: 22 | # record: false 23 | # # cache-key: node-v${{ matrix.node }}-on-${{ runner.os }}-hash-${{ hashFiles('package-lock.json') }} 24 | - name: publish 25 | env: 26 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 27 | run: | 28 | npm config set '//registry.npmjs.org/:_authToken' "${{ secrets.NPM_TOKEN }}" 29 | npm publish || true 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.sublime-workspace 2 | npm-debug.log 3 | 4 | .sass-cache/ 5 | _site/ 6 | node_modules/ 7 | cypress/videos/ 8 | cypress/screenshots/ 9 | .DS_Store 10 | .idea 11 | package-lock.json 12 | .jekyll-cache -------------------------------------------------------------------------------- /CYPRESS.md: -------------------------------------------------------------------------------- 1 | # Cypress 2 | 3 | ```bash 4 | npm i 5 | ``` 6 | 7 | run example blog with jekyll search build 8 | 9 | ```bash 10 | cd example 11 | jekyll serve 12 | ``` 13 | 14 | run cypress tests 15 | 16 | ```bash 17 | npm run cypress run 18 | # or 19 | npm run cypress open 20 | ``` 21 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Christian Fei 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [Simple-Jekyll-Search](https://www.npmjs.com/package/simple-jekyll-search) 2 | 3 | [![Build Status](https://img.shields.io/travis/christian-fei/Simple-Jekyll-Search/master.svg?)](https://travis-ci.org/christian-fei/Simple-Jekyll-Search) 4 | [![dependencies Status](https://img.shields.io/david/christian-fei/Simple-Jekyll-Search.svg)](https://david-dm.org/christian-fei/Simple-Jekyll-Search) 5 | [![devDependencies Status](https://img.shields.io/david/dev/christian-fei/Simple-Jekyll-Search.svg)](https://david-dm.org/christian-fei/Simple-Jekyll-Search?type=dev) 6 | 7 | A JavaScript library to add search functionality to any Jekyll blog. 8 | 9 | ## Use case 10 | 11 | You have a blog, built with Jekyll, and want a **lightweight search functionality** on your blog, purely client-side? 12 | 13 | *No server configurations or databases to maintain*. 14 | 15 | Just **5 minutes** to have a **fully working searchable blog**. 16 | 17 | --- 18 | 19 | ## Installation 20 | 21 | ### npm 22 | 23 | ```sh 24 | npm install simple-jekyll-search 25 | ``` 26 | 27 | ## Getting started 28 | 29 | ### Create `search.json` 30 | 31 | 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](/example/search.json)) 32 | 33 | This file will be used as a small data source to perform the searches on the client side: 34 | 35 | ```yaml 36 | --- 37 | layout: none 38 | --- 39 | [ 40 | {% for post in site.posts %} 41 | { 42 | "title" : "{{ post.title | escape }}", 43 | "category" : "{{ post.category }}", 44 | "tags" : "{{ post.tags | join: ', ' }}", 45 | "url" : "{{ site.baseurl }}{{ post.url }}", 46 | "date" : "{{ post.date }}" 47 | } {% unless forloop.last %},{% endunless %} 48 | {% endfor %} 49 | ] 50 | ``` 51 | 52 | 53 | ## Preparing the plugin 54 | 55 | ### Add DOM elements 56 | 57 | SimpleJekyllSearch needs two `DOM` elements to work: 58 | 59 | - a search input field 60 | - a result container to display the results 61 | 62 | #### Give me the code 63 | 64 | Here is the code you can use with the default configuration: 65 | 66 | 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) 67 | 68 | For example in **_layouts/default.html**: 69 | 70 | ```html 71 | 72 | 73 | 74 | 75 | 76 | 77 | ``` 78 | 79 | 80 | ## Usage 81 | 82 | Customize SimpleJekyllSearch by passing in your configuration options: 83 | 84 | ```js 85 | var sjs = SimpleJekyllSearch({ 86 | searchInput: document.getElementById('search-input'), 87 | resultsContainer: document.getElementById('results-container'), 88 | json: '/search.json' 89 | }) 90 | ``` 91 | 92 | ### returns { search } 93 | 94 | A new instance of SimpleJekyllSearch returns an object, with the only property `search`. 95 | 96 | `search` is a function used to simulate a user input and display the matching results.  97 | 98 | E.g.: 99 | 100 | ```js 101 | var sjs = SimpleJekyllSearch({ ...options }) 102 | sjs.search('Hello') 103 | ``` 104 | 105 | 💡 it can be used to filter posts by tags or categories! 106 | 107 | ## Options 108 | 109 | Here is a list of the available options, usage questions, troubleshooting & guides. 110 | 111 | ### searchInput (Element) [required] 112 | 113 | The input element on which the plugin should listen for keyboard event and trigger the searching and rendering for articles. 114 | 115 | 116 | ### resultsContainer (Element) [required] 117 | 118 | The container element in which the search results should be rendered in. Typically a `