From acdd3443de3152c8098b40bd28580d1634c26639 Mon Sep 17 00:00:00 2001 From: Michael Rose Date: Fri, 16 Feb 2018 14:20:42 -0500 Subject: [PATCH] Add Algolia search provider (#1531) * Support Lunr and Algolia search providers * Document search providers and configuration * Update CHANGELOG and history close #1416 --- CHANGELOG.md | 6 ++ _config.yml | 6 ++ _includes/scripts.html | 17 ++--- _includes/search/algolia-search-scripts.html | 54 ++++++++++++++++ _includes/search/lunr-search-scripts.html | 10 +++ _includes/search/search_form.html | 11 ++++ _includes/search_form.html | 4 -- _layouts/default.html | 2 +- _layouts/search.html | 15 +++-- _sass/minimal-mistakes/_search.scss | 18 ++++++ docs/_config.yml | 6 ++ docs/_docs/05-configuration.md | 67 ++++++++++++++++---- docs/_docs/18-history.md | 8 ++- test/Gemfile | 4 ++ test/_config.yml | 6 ++ test/_pages/search.md | 5 ++ 16 files changed, 206 insertions(+), 33 deletions(-) create mode 100644 _includes/search/algolia-search-scripts.html create mode 100644 _includes/search/lunr-search-scripts.html create mode 100644 _includes/search/search_form.html delete mode 100644 _includes/search_form.html create mode 100644 test/_pages/search.md diff --git a/CHANGELOG.md b/CHANGELOG.md index a0d1f6f1..d194056c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## Unreleased + +### Enhancements + +* Add support for [Algolia](https://www.algolia.com/) search provider. [#1416](https://github.com/mmistakes/minimal-mistakes/issues/1416) + ## [4.9.1](https://github.com/mmistakes/minimal-mistakes/releases/tag/4.9.1) ### Enhancements diff --git a/_config.yml b/_config.yml index 1a2694a1..ae4fe977 100644 --- a/_config.yml +++ b/_config.yml @@ -53,6 +53,12 @@ atom_feed: path : # blank (default) uses feed.xml search : # true, false (default) search_full_content : # true, false (default) +search_provider : # lunr (default), algolia +algolia: + application_id : # YOUR_APPLICATION_ID + index_name : # YOUR_INDEX_NAME + search_only_api_key : # YOUR_SEARCH_ONLY_API_KEY + powered_by : # true (default), false # SEO Related google_site_verification : diff --git a/_includes/scripts.html b/_includes/scripts.html index 45113e09..ded8e7ba 100644 --- a/_includes/scripts.html +++ b/_includes/scripts.html @@ -13,16 +13,13 @@ {% endif %} {% if site.search == true or page.layout == "search" %} - {% assign lang = site.locale | slice: 0,2 | default: "en" %} - {% case lang %} - {% when "gr" %} - {% assign lang = "gr" %} - {% else %} - {% assign lang = "en" %} - {% endcase %} - - - + {%- assign search_provider = site.search_provider | default: "lunr" -%} + {%- case search_provider -%} + {%- when "lunr" -%} + {% include search/lunr-search-scripts.html %} + {%- when "algolia" -%} + {% include search/algolia-search-scripts.html %} + {%- endcase -%} {% endif %} {% include analytics.html %} diff --git a/_includes/search/algolia-search-scripts.html b/_includes/search/algolia-search-scripts.html new file mode 100644 index 00000000..1ec021df --- /dev/null +++ b/_includes/search/algolia-search-scripts.html @@ -0,0 +1,54 @@ + + + + + + diff --git a/_includes/search/lunr-search-scripts.html b/_includes/search/lunr-search-scripts.html new file mode 100644 index 00000000..b8ffc231 --- /dev/null +++ b/_includes/search/lunr-search-scripts.html @@ -0,0 +1,10 @@ +{% assign lang = site.locale | slice: 0,2 | default: "en" %} +{% case lang %} +{% when "gr" %} + {% assign lang = "gr" %} +{% else %} + {% assign lang = "en" %} +{% endcase %} + + + \ No newline at end of file diff --git a/_includes/search/search_form.html b/_includes/search/search_form.html new file mode 100644 index 00000000..3058f6b1 --- /dev/null +++ b/_includes/search/search_form.html @@ -0,0 +1,11 @@ +
+{%- assign search_provider = site.search_provider | default: "lunr" -%} +{%- case search_provider -%} + {%- when "lunr" -%} + +
+ {%- when "algolia" -%} + +
+{%- endcase -%} +
\ No newline at end of file diff --git a/_includes/search_form.html b/_includes/search_form.html deleted file mode 100644 index b9bf70fd..00000000 --- a/_includes/search_form.html +++ /dev/null @@ -1,4 +0,0 @@ -
- -
-
\ No newline at end of file diff --git a/_layouts/default.html b/_layouts/default.html index de670038..7a82a808 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -25,7 +25,7 @@ {% if site.search == true %}
- {% include search_form.html %} + {% include search/search_form.html %}
{% endif %} diff --git a/_layouts/search.html b/_layouts/search.html index 8f5c2159..1bac452c 100644 --- a/_layouts/search.html +++ b/_layouts/search.html @@ -22,11 +22,14 @@ layout: default {{ content }} -
- -
- -
- + {%- assign search_provider = site.search_provider | default: "lunr" -%} + {%- case search_provider -%} + {%- when "lunr" -%} + +
+ {%- when "algolia" -%} + +
+ {%- endcase -%} diff --git a/_sass/minimal-mistakes/_search.scss b/_sass/minimal-mistakes/_search.scss index 1e23c336..fe3c4367 100644 --- a/_sass/minimal-mistakes/_search.scss +++ b/_sass/minimal-mistakes/_search.scss @@ -105,3 +105,21 @@ margin-bottom: 0; } } + +/* Algolia search */ + +.ais-search-box { + max-width: 100% !important; + margin-bottom: 2em; +} + +.archive__item-title .ais-Highlight { + color: $link-color; + font-style: normal; + text-decoration: underline; +} +.archive__item-excerpt .ais-Highlight { + color: $link-color; + font-style: normal; + font-weight: bold; +} diff --git a/docs/_config.yml b/docs/_config.yml index 992bdb5b..ded54b54 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -57,6 +57,12 @@ atom_feed: search : true # true, false (default) search_full_content : true # true, false (default) +search_provider : lunr # lunr (default), algolia +algolia: + application_id : # YOUR_APPLICATION_ID + index_name : # YOUR_INDEX_NAME + search_only_api_key : # YOUR_SEARCH_ONLY_API_KEY + powered_by : # true (default), false # SEO Related google_site_verification : "UQj93ERU9zgECodaaXgVpkjrFn9UrDMEzVamacSoQ8Y" # Replace this with your ID, or delete diff --git a/docs/_docs/05-configuration.md b/docs/_docs/05-configuration.md index 0e9f682b..d3d470db 100644 --- a/docs/_docs/05-configuration.md +++ b/docs/_docs/05-configuration.md @@ -2,7 +2,7 @@ title: "Configuration" permalink: /docs/configuration/ excerpt: "Settings for configuring and customizing the theme." -last_modified_at: 2018-02-01T14:40:00-05:00 +last_modified_at: 2018-02-16T12:49:45-05:00 toc: true --- @@ -468,23 +468,68 @@ atom_feed: ### Site Search -Enable basic site search powered by [Lunr](https://lunrjs.com/) by adding the following to `_config.yml`: - -```yaml -search: true -``` +To enable site-wide search add `search: true` to your `_config.yml`. ![masthead search example]({{ "/assets/images/masthead-search.gif" | absolute_url }}) -To index the full content of your documents set `search_full_content` to `true` in `_config.yml`: +#### Lunr (default) -```yaml -search_full_content: true -``` +The default search uses [**Lunr**](https://lunrjs.com/) to build a search index of all your documents. This method is 100% compatible with sites hosted on GitHub Pages. -**Note:** Large amounts of posts will increase the size of the search index, impacting page load performance. Setting `search_full_content` to `false` (the default) restricts indexing to the first 50 words of body content. +**Note:** Only the first 50 words of a post or page's body content is added to the Lunr search index. Setting `search_full_content` to `true` in your `_config.yml` will override this and could impact page load performance. {: .notice--warning} +#### Algolia + +For faster and more relevant search ([see demo](https://mmistakes.github.io/jekyll-theme-basically-basic-algolia-search/)): + +1. Add the [`jekyll-algolia`](https://github.com/algolia/jekyll-algolia) gem to your `Gemfile`, in the `:jekyll_plugins` section. + + ```ruby + group :jekyll_plugins do + gem "jekyll-feed" + gem "jekyll-seo-tag" + gem "jekyll-sitemap" + gem "jekyll-paginate" + gem "jekyll-algolia" + end + ``` + + Once this is done, download all dependencies by running `bundle install`. + +2. Switch search providers from `lunr` to `algolia` in your `_config.yml` file: + + ```yaml + search_provider: algolia + ``` + +3. Add the following Algolia credentials to your `_config.yml` file. *If you don't have an Algolia account, you can open a free [Community plan](https://www.algolia.com/users/sign_up/hacker). Once signed in, you can grab your credentials from [your dashboard](https://www.algolia.com/licensing).* + + ```yaml + algolia: + application_id: # YOUR_APPLICATION_ID + index_name: # YOUR_INDEX_NAME + search_only_api_key: # YOUR_SEARCH_ONLY_API_KEY + powered_by: # true (default), false + ``` + +4. Once your credentials are setup, you can run the indexing with the following command: + + ``` + ALGOLIA_API_KEY=your_admin_api_key bundle exec jekyll algolia + ``` + + For Windows users you will have to use `set` to assigned the `ALGOLIA_API_KEY` environment variable. + + ``` + set ALGOLIA_API_KEY=your_admin_api_key + bundle exec jekyll algolia + ``` + + Note that `ALGOLIA_API_KEY` should be set to your admin API key. + +To use the Algolia search with GitHub Pages hosted sites follow [this deployment guide](https://community.algolia.com/jekyll-algolia/github-pages.html). Or this guide for [deploying on Netlify](https://community.algolia.com/jekyll-algolia/netlify.html). + ### SEO, Social Sharing, and Analytics Settings All optional, but a good idea to take the time setting up to improve SEO and links shared from the site. diff --git a/docs/_docs/18-history.md b/docs/_docs/18-history.md index 908ae080..0995d270 100644 --- a/docs/_docs/18-history.md +++ b/docs/_docs/18-history.md @@ -4,10 +4,16 @@ permalink: /docs/history/ excerpt: "Change log of enhancements and bug fixes made to the theme." sidebar: nav: docs -last_modified_at: 2018-02-05T14:38:43-05:00 +last_modified_at: 2018-02-16T12:45:12-05:00 toc: true --- +## Unreleased + +### Enhancements + +* Add support for [Algolia](https://www.algolia.com/) search provider. [#1416](https://github.com/mmistakes/minimal-mistakes/issues/1416) + ## [4.9.1](https://github.com/mmistakes/minimal-mistakes/releases/tag/4.9.1) ### Enhancements diff --git a/test/Gemfile b/test/Gemfile index 5ac85127..8c142a8a 100644 --- a/test/Gemfile +++ b/test/Gemfile @@ -3,4 +3,8 @@ source "https://rubygems.org" # use local theme gem for testing gem "minimal-mistakes-jekyll", path: "../" +group :jekyll_plugins do + gem 'jekyll-algolia', '~> 1.0' +end + gem "wdm", "~> 0.1.0" if Gem.win_platform? \ No newline at end of file diff --git a/test/_config.yml b/test/_config.yml index 4222bc93..66b902ea 100644 --- a/test/_config.yml +++ b/test/_config.yml @@ -51,6 +51,12 @@ atom_feed: path : # blank (default) uses feed.xml search : true # true, false (default) search_full_content : true # true, false (default) +search_provider : "algolia" +algolia: + application_id : "QB6HVGBSBA" + index_name : "dev_minimal-mistakes" + search_only_api_key : "9d5014e5bbc77372547bce778dfa5663" + powered_by : true # SEO Related google_site_verification : diff --git a/test/_pages/search.md b/test/_pages/search.md new file mode 100644 index 00000000..9a056492 --- /dev/null +++ b/test/_pages/search.md @@ -0,0 +1,5 @@ +--- +title: Search +layout: search +permalink: /search/ +--- \ No newline at end of file