diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b6b622..0a04525 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased +### Added +- Add site-wide search toggle. +- Add support for Lunr search. [#48](https://github.com/mmistakes/jekyll-theme-basically-basic/pull/48) +- Add support for Algolia search. [#48](https://github.com/mmistakes/jekyll-theme-basically-basic/pull/48) + ### Changed - New installation and upgrade instructions. +- Absolutely position navigation menu instead of sticking it to the top. +- Visually hide "Menu" label. +- Improve alignment of menu toggle when search is enabled. ### Fixed - Fix `border-bottom` for Gist line numbers. diff --git a/README.md b/README.md index 4b62a1a..07408be 100644 --- a/README.md +++ b/README.md @@ -42,10 +42,13 @@ with a few enhancements thrown in for good measure: 3. [Text](#text) 4. [Navigation](#navigation) 5. [Pagination](#pagination) - 6. [Author](#author) - 7. [Reading Time](#reading-time) - 8. [Comments (via Disqus)](#comments-via-disqus) - 9. [Google Analytics](#google-analytics) + 6. [Search](#search) + 1. [Lunr (default)](#lunr-default) + 2. [Algolia](#algolia) + 7. [Author](#author) + 8. [Reading Time](#reading-time) + 9. [Comments (via Disqus)](#comments-via-disqus) + 10. [Google Analytics](#google-analytics) 5. [Layouts](#layouts) 1. [`layout: default`](#layout-default) 2. [`layout: post`](#layout-post) @@ -63,9 +66,6 @@ with a few enhancements thrown in for good measure: 8. [Contributing](#contributing) 1. [Pull Requests](#pull-requests) 9. [Credits](#credits) - 1. [Creator](#creator) - 2. [Icons + Demo Images:](#icons--demo-images) - 3. [Other:](#other) 10. [License](#license) ## Installation @@ -402,6 +402,67 @@ add the following front matter: paginate: true ``` +### Search + +To enable site-wide search add `search: true` to your `_config.yml`. + +#### Lunr (default) + +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:** 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. + +#### Algolia + +For faster and more relevant 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). + ### Author Author information is used as meta data for post "by lines" and propagates the diff --git a/_config.yml b/_config.yml index 18da4f1..7431bef 100644 --- a/_config.yml +++ b/_config.yml @@ -26,6 +26,14 @@ author: twitter_username: github_username: logo: # path of site logo, e.g. "/assets/images/logo.png" +search: # true, false (default) +search_full_content: false # 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 # Build settings markdown: kramdown diff --git a/_data/theme.yml b/_data/theme.yml index 89242ea..1e82c26 100644 --- a/_data/theme.yml +++ b/_data/theme.yml @@ -8,6 +8,9 @@ t: skip_content: "Skip to content" skip_footer: "Skip to footer" menu: "Menu" + search: "Search" + results_found: "Result(s) found" + search_placeholder_text: "Enter your search term..." home: "Home" newer: "Newer" older: "Older" diff --git a/_includes/scripts.html b/_includes/scripts.html index 85a2a21..08bbe61 100644 --- a/_includes/scripts.html +++ b/_includes/scripts.html @@ -2,4 +2,15 @@ {% include google-analytics.html %} {% endif %} - \ No newline at end of file + + + +{% if site.search %} + {%- 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 %} diff --git a/_includes/search-form.html b/_includes/search-form.html new file mode 100644 index 0000000..7c2cfeb --- /dev/null +++ b/_includes/search-form.html @@ -0,0 +1,13 @@ +
+ {% if site.search %} + {%- assign search_provider = site.search_provider | default: "lunr" -%} + {%- case search_provider -%} + {%- when "lunr" -%} + +
+ {%- when "algolia" -%} + +
+ {%- endcase -%} + {% endif %} +
diff --git a/_includes/search/algolia-search-scripts.html b/_includes/search/algolia-search-scripts.html new file mode 100644 index 0000000..cda2cc4 --- /dev/null +++ b/_includes/search/algolia-search-scripts.html @@ -0,0 +1,52 @@ + + + + + + diff --git a/_includes/search/lunr-search-scripts.html b/_includes/search/lunr-search-scripts.html new file mode 100644 index 0000000..30e9d42 --- /dev/null +++ b/_includes/search/lunr-search-scripts.html @@ -0,0 +1,106 @@ +{%- assign lang = site.lang | slice: 0, 2 | default: "en" -%} + {%- case lang -%} + {%- when "da" -%} + {%- assign lang = "da" -%} + {%- when "de" -%} + {%- assign lang = "de" -%} + {%- when "du" -%} + {%- assign lang = "du" -%} + {-% when "es" -%} + {%- assign lang = "es" -%} + {%- when "fi" -%} + {%- assign lang = "fi" -%} + {%- when "fr" -%} + {%- assign lang = "fr" -%} + {%- when "hu" -%} + {%- assign lang = "hu" -%} + {%- when "it" -%} + {%- assign lang = "it" -%} + {%- when "ja" -%} + {%- assign lang = "ja" -%} + {%- when "jp" -%} + {%- assign lang = "jp" -%} + {%- when "no" -%} + {%- assign lang = "no" -%} + {%- when "pt" -%} + {%- assign lang = "pt" -%} + {%- when "ro" -%} + {%- assign lang = "ro" -%} + {%- when "ru" -%} + {%- assign lang = "ru" -%} + {%- when "sv" -%} + {%- assign lang = "sv" -%} + {%- when "tr" -%} + {%- assign lang = "tr" -%} + {%- else -%} + {%- assign lang = "en" -%} + {%- endcase -%} + + + {%- unless lang == "en" -%} + + + {%- endunless %} + diff --git a/_layouts/default.html b/_layouts/default.html index 4f7c575..f0026b6 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -13,9 +13,18 @@ {% include skip-links.html %}