Add a feature-rich search box in your JAM stack website
Overview
- Alternatives to process search
- Test drive search on Algolia’s Jekyll-Hyde theme’s demo site online
- Get it working locally
- Edit the repo so your own posts are indexed
- Add search features to a base theme
- Resources
- More on front-end styling
The objective of this article is for you to implement these use cases (click on the underlined items to go straight there):
https://wilsonmar.github.io/jekyll-with-algolia-search = https://goo.gl/UWKgTu
-
Test drive search on a demo site online.
The site is built with Jekyll and can perform text search on pre-defined text content.
-
Get a sample theme on your local machine working with search queries.
We setup your machine with Jekyll and Ruby, then clone a fork of a famous Jekyll theme adapted with search capabilities.
-
Edit the repo so your own posts are indexed.
We obtain API keys for a new account on the search service and use it to index new posts we add.
-
Add search features to another theme.
We deep dive into the theme to add JavaScript, CSS, and HTML.
Before we dive into Alogolia, know this:
Alternatives to process search
Other options to add search capabilities on a Jekyll site:
- Mike Neumegen of @CloudCannonApp has a video blog showing how to add search using lunr.js to the bakery-store theme on GitHub of his own design. There is a tutorial on how to contruct it.
Alas, [4:50] near the end of this 5-minute video:
“Where it really falls down is if you have a large site, you need all your search data in a JSON file which has to be downloaded by the client. So if you have hundreds of blog posts, it’s going to be really slow if you try to implement it using lunr.”
Search in Azure
Adding Search Abilities to Your Apps with Azure Search (cloud) 2h 55m video by Chad Campbell (@ChadCampbell, ecofic.com) explains natural language processing for 35 languages (such as searching for “went” when the request is for “go”) and Geospatial around a point or within an area.
But scalability means manual editing in the Azure Portal or programming Azure Search Management APIs.
Use Scoring Profile to align searches.
Test drive search on Algolia’s Jekyll-Hyde theme’s demo site online
-
Click this link to go to our theme’s demo website on-line:
http://community.algolia.com/algoliasearch-jekyll-hyde/
The formatting of this site is what you’ll have as YOUR blog after following instructions in this tutorial.
Search Demo steps
-
Type in the search field a single letter such as “L”.
-
Do results appear as you type? It should.
-
Do you need to click a submit button? No.
-
Are results highlighted within the normal presentation rather than with a different format, such as with Bing or Google search?
-
-
Click another link (Home) and try search term “Love craxy” (with a capital letter and a misspelling).
-
Is it “typo tolerant” (“crazy” is found even though it was typed in wrong as “craxy”).
-
Are capital letters and lower case letters equivalent?
Thus, as far as search goes, the theme presented is rather complete. Well, almost.
404 Search Redirect
-
-
Change the URL to a post that should not exist, such as:
http://community.algolia.com/algoliasearch-jekyll-hyde/whatever
- Are you redirected to a search page with “whatever” in the search field?
No.
NOTE: I’ve filed an issue to request this feature.
- Are you redirected to a search page with “whatever” in the search field?
No.
Missing features
We are using a pre-formatted theme rather than design-your-own, which takes much more time and expertise.
Features not in the theme would need to be added.
Get it working locally
Here are the steps setup your own free static website that provides a search box:
- Create a GitHub account
- Clone a Jekyll template
- Install Ruby, Jekyll, Build gems
- Run website locally
- Create a Shell Script to Run Jekyll Locally
- Customize website locally
- Update Alogria code locally
The architectural components is call the JAM stack, with JAM standing for JavaScript, APIs, and Markup. The order of the components has no significance (there had to be a vowel in the second letter).
JAM is a fast-growing stack for building websites and apps:
- No database servers that take time to retrieve
-
No construction of web pages to respond to a request
- Markup in text files within GitHub for version control
- Markup files are pre-processed into display-ready HTML
-
HTML files can be stored on various servers around the world in a CDN
- JavaScript calls APIs for any moving parts (such as retrieving personalization data)
Create a GitHub Account
In this tutorial, we refer to your_account as the account name you created in GitHub.
If you already have an account, skip this section.
-
Click on this URL to open an internet browser to:
-
Sign-up with a user name you pick (one that’s not already taken).
NOTE: The remainder of this tutorial refers to “acme” in place of YOUR real user/account name.
-
Confirm your email.
Fork and rename template altered by Alogolia
Templates provide pre-formatted CSS and JavaScript. Themes are available from a variety of sources.
We like Jekyll over WordPress, Drupal, and other frameworks because unlike them others, Jekyll’s blog entries are stored in text files rather in a database. This makes it easier to switch Jekyll themes.
The theme we are using in this tutorial is based on a fork of the Hyde theme template, which is among the most popular partly because it is created by the legendary Mark Otto, Director of Design at GitHub.
-
Mobile friendly design and development
-
Easily scalable text and component sizing with rem units in the CSS
The steps:
-
Click the link below to open an internet browser with our base theme:
https://github.com/algolia/algoliasearch-jekyll-hyde
This theme adds a search box to the Hyde theme by adding additional HTML, CSS, configuration settings, and JavaScript programming.
We will examine each change below.
-
Click its Fork button to put it under your GitHub account.
-
Click the Settings tab to rename the repo, as your_account_name.github.io.
In other words, if your account name is “acme”, you would rename the repo to acme.github.io.
NOTE: “github.io” means the site is hosted by GitHub, which does not charge (unlike GoDaddy or other hosting provider).
PROTIP: Sites hosted on GitHub.io can still have a custom name such as “acme.com”.
Next, we’ll download the repository.
Install Git Client
There are several choices.
-
Mac machine already have a command-line Git client.
-
Follow this website to install Git in Windows
Create a local repo
-
Open a Terminal Shell Window on the Mac or cmd program on Windows.
-
PROTIP: Create a folder path to clone (create) repositories into.
mkdir ~/gits
cd gitsRepos are created within this folder.
-
PROTIP: Create a folder to hold all Git repositories from your account.
And change directory into it:
mkdir ~/gits/your_account
cd your_accountOn Mac and Linux, the ~ (tilde) character designates the current user’s home folder.
-
Clone from your_account on GitHub:
git clone https://github.com/your_account/your_account.github.io
-
View folder.
cd your_account.github.io
NOTE: Cloning creates .git folder that contains all the history in the creation of the template. This file is what enables Git version control.
-
Compare this against the standard structure.
Notice the .jekyll-metadata entry keeps the file’s data local. It will NOT be sent back up to GitHub.
-
Use a text editor to view the .gitignore file.
The presence of the _site line means that the _site folder generated will NOT be sent back up to GitHub because GitHub will generate its own _site folder.
-
Use a text editor to create a _config-dev.yml file containing:
# Develop override settings url: http://localhost:4001
Install Ruby and Jekyll, Build gems
Text in Jekyll sites are written in “Markdown” format which Jekyll converts to HTML that site vistors download and display on their internet browsers.
The programming for Jekyll to do that is written in the Ruby programming language.
-
Install the Ruby program compiler on a Mac
Alternately, install Ruby on Windows.
Gems contain Ruby programs in a way that can be easily installed.
-
Install Jekyll as a Ruby gem:
gem install jekyll
This automatically install dependencies.
-
Use a text editor to open the Gemfile.
source 'https://rubygems.org' gem 'jekyll', '~> 2.5' group :jekyll_plugins do gem 'algoliasearch-jekyll', '~> 0.4' end
NOTE: If you are adding search capability to an existing site, you would add gem specifications to this file.
-
Click the URL to visit:
NOTE: Gems specified are pulled from the Rubygems website.
-
Search for algoliasearch-jekyll:
https://rubygems.org/gems/algoliasearch-jekyll/
The development dependencies are libraries used during code programming:
- coveralls ~> 0.8 takes json-cov output into stdin and POSTs to coveralls.io
- flay ~> 2.6
- flog ~> 4.3 light-weight configurable front-end logger
- guard-rspec ~> 4.6
- jeweler ~> 2.0
- rspec ~> 3.0
- rubocop ~> 0.31
- simplecov ~> 0.10
Run-time dependencies are what needs to be specified in the Gemfile:
- algoliasearch ~> 1.4
- appraisal ~> 2.1.0
- awesome_print ~> 1.6
- json ~> 1.8
- nokogiri ~> 1.6
- verbal_expressions ~> 0.1.5
-
In a Terminal window, have dependency gems automatically fetched based on the Gemfile and dependencies:
bundle install
Install is the default action.
NOTE: The Gemfile.lock file generated defines the version being used of each gem.
Run Jekyll Locally
-
To ensure you have a base version that works locally, run:
bundle exec jekyll serve --config _config.yml,_config-dev.yml --port 4001
The sample response:
Source: /Users/mac/gits/acme/acme.github.io Destination: /Users/mac/gits/acme/acme.github.io/_site Generating... done. Auto-regeneration: enabled for '/Users/mac/gits/acme/acme.github.io' Server address: http://127.0.0.1:4001/ Server running... press ctrl-c to stop.
If an error message appears about port 4000 (the default), it may be because two dashes need to precede the port parameter keyword.
On a Mac, “ctrl-c” means hold down the control key and press C to stop.
NOTE: A _site folder should now be generated.
-
Switch to an internet browser to open the server address:
BTW, documentation on all configuration options:
Create a Shell Script to Run Jekyll Locally
PROTIP: Create a script instead of typing in the long command, to save time and avoid mistakes.
Mac and Linux Shell Script
-
Use a text editor program to create a file named 4001.sh</strong>.
-
Save the file in the root folder of the Jekyll repository.
- Open a Terminal instance and navigate to that repository.
-
Define run permissions:
chmod a+x 4001.sh
Windows Shell Script
-
Use a text editor program to create a file named 4001.cmd</strong>.
-
Save the file in the root folder of the Jekyll repository.
-
Open cmd program and navigate to that Jekyll folder.
Run script
Run script on MacOS
-
Open a Terminal instance to run it:
./4001.sh
Run script on Windows
-
Run it in a command window:
4001.cmd
Update Alogria code locally
Since Algoria is good enough to update its example over time to reflect for changes by authors of the Jekyll base and the Hyde template, you’ll need to update the Aloglia sample, but without messing without disturbing your configuration changes.
-
PROTIP: Make a zip of your folder so you’ll have an easy fall-back.
-
In a command-line window, ensure there is a remote:
git remote -v
Expect:
upstream https://github.com/algolia/algoliasearch-jekyll-hyde (fetch) upstream https://github.com/algolia/algoliasearch-jekyll-hyde (push)
If the above does not appear:
git remote add upstream https://github.com/algolia/algoliasearch-jekyll-hyde
Verify the remote again.
-
Use Git to fetch branches and their contents (with history):
git fetch upstream -v
Sample response:
From https://github.com/algolia/algoliasearch-jekyll-hyde * [new branch] gh-pages -> algolia/gh-pages * [new branch] issue/command-not-found -> algolia/issue/command-not-found * [new branch] jekyll-v3 -> algolia/jekyll-v3 * [new branch] master -> algolia/master * [new branch] pr -> algolia/pr * [new branch] test/algolia-v1 -> algolia/test/algolia-v1
- Identify the branch you want to update. This is typically “master”.
-
Checkout that branch:
git checkout –track upstream/master
-
Verify that branch:
git status
-
Review the changes:
git ???
-
Update gem dependencies:
gem update
The response:
Updating installed gems
-
Resolve conflicts, if any.
-
Update dependencies:
bundle install
- Make site changes public on GitHub later after configuration and testing.
Edit the repo so your own posts are indexed
You want your own content instead of the postings copied from the theme, right?
There are several customizations:
- Setup your own indexing service
- Configure _config.yml
- Specify Write API KEY
- Index in shell script
- Adjust theme colors and presentation
- Add new custom posts
- View refreshed site
- Make site changes public on GitHub
- Replace site icon
- View Logs and Metrics
Setup your own indexing service
-
Sign-up at Algolia.com (you can optionally use your GitHub credentials).
A free account of up to 10,000 requests per day is available from Algolia.com.
This video by Tim Carry (tim@algolia.com) illustrates his blog article:
-
Specify the name and region where the majority of your visitors are located.
Algoria’s UI has a cool list of live ping response times to various regions:
-
Look at the email for links to their thorough demos and tutorials (doc), which populates your instance with example of actors.
Configure _config.yml
NOTE: Jekyll keeps its configuration information in a text file named _config.yml.
-
Use a text editor to open the _config.yml file.
Site title
-
Manually change these values in the sample file:
title: Hyde tagline: 'A Jekyll theme, with instant search' description: 'The popular Hyde theme for Jekyll, now with instant-search capabilities. Made by @mdo and Algolia'
-
Save the file and restart the server to see your changes on the website.
Site URL
-
Click Find and Replace from
algolia/algoliasearch-jekyll-hyde
to, for example:
acme/acme.github.io
would change these lines:
url: https://github.com/algolia/algoliasearch-jekyll-hyde baseurl: /algoliasearch-jekyll-hyde
Site API KEY
-
Switch to an internet browser with the Algolia Dashboard on your account.
The value you see for application_id would be different that the example shown here.
-
Copy the value of the Application ID by clicking on the icon to the right of each value or highlight each value and press Ctrl+C.
NOTE: A Jekyll plugin (from Algolia or another) extracts every paragraph of text (between
<p>
and</p>
tags) from HTML files generated by the jekyll build command. This approach of reading the final HTML pages instead of markdown text works with any markdown parser and custom plugin. -
Use a text editor to open the _config.yml file and paste in this under the gems: section:
gems: - algoliasearch-jekyll algolia: application_id: 'EILX55I5BP' index_name: 'jekyll_PROD' read_only_api_key: '6be0576ff61c053d5f9a3225e2a90f76' excluded_files: - 404.html - index.html
application_id
-
Highlight to value for application_id and paste yours to replace it.
read_only_api
-
As above, copy from the Dashboard the Search-Only API Key and replace the value of read_only_api_key in the _config.yml file.
index_name
NOTE: The Algolia plugin also adds metadata context to each paragraph before pushing the lot to the Algolia index in the cloud.
PROTIP: Specify a different index name for PROD and TEST so you don’t mix different data.
-
In _config.yml specify a index name such as “jekyll_PROD”.
-
In _config-dev.yml specify a index name such as “jekyll_TEST”.
NOTE: With Aloglia, an index does not need to be created manually ahead of index insertion.
-
Save the file and restart the server to see your changes on the website. The response looks like this:
Configuration file: /Users/mac/gits/jetbloom/jetbloom.github.io/_config.yml Indexing 822 items Indexing of 822 items in jekyll_PROD done.
Create _algolia_api_key
PROTIP: Keep private from the world API keys with write permissons.
- Use a text editor to open file .gitignore file.
-
Scroll to the bottom of the file to copy the _algolia_api_key entry.
Functions in the Algolia JavaScript client library downloaded open a file with this name to retrieve the contents for use like a password associated with write and delete permissions.
- Close the file.
-
Switch to an internet browser with the Algolia Dashboard on your account.
-
Click the icon to the right of the Admin API Key value to copy it into your Clipboard.
The key’s value is shown as dots in case someone else is looking over your shoulder.
- Switch back to the text editor to open a new file.
- Paste the API key in the file.
- Save the file in the repo folder as name _algolia_api_key (no file extension).
- Close the file.
Index in shell script
PROTIP: Combine several actions in the custom shell script, such as building the index.
-
Use a text editor to edit the 4001.sh or 4001.cmd script created above to Run Jekyll locally.
-
Identify the sub-modules installed:
bundle exec jekyll -h
The algolia sub-command should be listed.
-
Replace the 4001 script file with this:
# build _site folder: bundle exec jekyll build –config _config.yml,_config-dev.yml # Index sub-command: bundle exec jekyll algolia push # Display: bundle exec jekyll serve –config _config.yml,_config-dev.yml --port 4001
This is constructed based on Jekyll documentation at https://jekyllrb.com/docs/usage/
NOTE: The jekyll aloglia sub-command references the _algolia_api_key.
Repeat your Ruby install and bundle install if you see this message:
fatal: 'jekyll algolia' could not be found. You may need to install the jekyll-algolia gem or a related gem to be able to use this subcommand.
Update indexes in Continuous Integration
PROTIP: Update indexes using a continuous integration server set to automatically push data and reindex upon save.
There are several CI servers:
TODO: Add CI settings instructions.
- Jenkins
- Cloudbees SaaS running Jenkins
- TravisCI
- CircleCI
Adjust theme colors and presentation
Some themes pre-code alternative CSS that can be selected.
The Hyde theme at https://github.com/poole/hyde explains some changes in the format of the site’s layout. To change the color scheme of the site to green and flip the menu to the right side, change _layouts/default.html from:
<body class="theme-base-09">
to:
<body class="theme-base-0b layout-reverse">
The disadvantage of this convenience is that the CSS file can become “bloated”, and require longer to load by visitors.
Add new custom posts
NOTE: Content shown on Jekyll websites are defined as individual files within the _posts folder. This is a key differentiator of Jekyll vs. WordPress, Drupal, and others that store content in a database.
Files in the _posts folder can be moved among different Jekyll themes.
-
Use a text editor to open an .md file within the _posts folder.
Files names end with “.md” to designate markdown formatting. Jekyll processes such files into index.html files.
There are other formats, such as
Some text editors can provide text highlighting based on the file extension.
The three dashes in the first line begins the “front matter” which Jekyll processes.
--- layout: post title: Let's start the adventure author: login: nicolas email: nicolas@algolia.com display_name: nicolas first_name: Nicolas last_name: Dessaigne ---
NOTE: The
post
value inlayout: post
means that the post.html file in the _layouts folder is used to format text in the file. -
Replace the title and author.
NOTE: Some other themes provide a default author so it doesn’t have to be entered on every post.
- Erase the remainder after the front matter (three dashes).
- Save the file with a different file name.
- View site again.
View refreshed site
-
Switch to the Terminal window running Jekyll.
Jekyll is set to detect changes to the file and re-generate HTML as needed.
Regenerating: 1 file(s) changed at 2016-05-30 11:03:55 ...done in 5.612279 seconds.
-
Switch to the internet browser and press Ctrl+R or click the icon to refresh the screen.
Erase sample posts
- Switch to the Finder on a Mac or File Explorer on Windows.
- Navigate to the _posts folder.
- Select all files in the folder except the one created above.
- Delete files selected.
Make site changes public on GitHub
PROTIP: Make a small change, then add and commit.
-
If you use a command-line Git client:
git add .
git commit -m”Add sample posts” -
See if there is a remote local defined:
git remote -v
-
If there isn’t, define one (replacing the URL with yours):
git remote add remote https://github.com/acme/acme.github.io
-
Verify with another:
git remote -v
origin http://github.com/acme/acme.github.io (fetch) origin http://github.com/acme/acme.github.io (push)
-
Push commits to GitHub to verify the site running before customization.
git push
-
View your site using the public URL.
View Logs and Metrics
On the search service Dashboard:
NOTE: Alogia emails the number of calls each day.
Add search features to a base theme
NOTE: This section is not complete yet.
To add search features to another Jekyll theme, we dive into theme JavaScript, CSS, HTML, and configuration files.
PROTIP: The sequence in the video above shows a sequence of changes so you can make one change at a time and have it still working so you can verify each change.
- Get a copy of your custom theme working on your local machine
- Add a link to the algolia.css file in _includes/head.html
- Specify in .gitignore the file containing private keys
- Edit _config.yml to add your Algolia credentials
- Edit Gemfile (if you’re using bundler) to add the Jekyll Algolia plugin
- Edit _includes/footer.html to include the links to the needed JS files and templates
- Edit_includes/sidebar.html to add the search input
- Edit_layouts/default.html to replace the element where content is usually displayed and transform it into two elements. One for the “static” display (current blog post for example) and one for the “dynamic” display (search results). Only one of the two will be visible at a time, depending if the user is searching or reading
public/css/search.css where you put all the search-specific styling (input, results, etc)
- public/js/search.js where you put the search-specific javascript (instanciating the Algolia client, updating the render, etc)
Get a base theme working on your local machine.
My Jekyll Templates page lists several.
As an example, we’ll be modifying the Hyde theme since we’re already familiar with its look and feel.
PROTIP: We modify the theme so that we can test the effectiveness of each step.
-
Open an internet browser to see the base theme demo:
-
Click the link below to open the GitHub page for the theme:
We will add a search box by adding additional HTML, CSS, configuration settings, and JavaScript programming.
-
Click its Fork button to put it under your GitHub account.
-
Click “Clone or download”, then Download Zip.
-
Use Finder to open the “hyde-master.zip” in the Downloads folder.
-
Unzip it.
-
Move the folder to a directory such as “~/gits/jekyll”.
NOTE: The folder does not contain a Gemfile.
- Navigate to that folder.
-
Run Jekyll server to display the static site:
jekyll serve
-
Add a link to the algolia.css file in _includes/head.html
<link rel="stylesheet" href="public/css/algolia.css">
To check if this works, use your browser Debugger’s waterfall chart.
-
Add CSS to style the search form and search results based on the contents within:
https://github.com/algolia/algoliasearch-jekyll-hyde/blob/master/public/css/algolia.css
What you actually add can be much different if you prefer to make use of SASS, etc.
/* Search form */ .algolia__form { margin-bottom: 1rem; } .algolia__input { font-size: 20px; padding:.25rem .5rem; } /* Search results */ .algolia__initial-content { display:block; } .algolia__initial-content--hidden { display:none; } .algolia__search-content { display:none; } .algolia__search-content--active { display:block; } .algolia__result-link { font-size: 1.25rem; font-weight:bold; } .algolia__result-date { font-size:0.8rem; } .algolia__result-text { } .algolia__result-highlight { background: yellow; color:inherit; }
You won’t be able to check if this works until the form is added, below.
-
Add the search form input field in the sidebar.html within _includes.
Different templates use varying techniques to provide a form field for visitors to specify search terms.
After saving, the form should appear. Adjust the CSS styling and positioning as you wish.
-
Add the algolia.js library of JavaScript functions into the repo, such as the public/js folder.
https://github.com/algolia/algoliasearch-jekyll-hyde/blob/master/public/js/algolia.js
-
Add the HTML to display page titles and content in default.html within folder _layouts:
<div class="content container"> <div class="algolia__initial-content js-algolia__initial-content">\{\{ content \}\}</div> <div class="algolia__search-content js-algolia__search-content"> <h1 class="page-title">Search</h1> <div class="posts algolia__results"></div> </div> </div>
-
Add HTML links to the Algolia library within the HTTP footer.html within the _includes folder.
<script> window.ALGOLIA_CONFIG = { 'applicationId': 'EILX55I5BP', 'indexName': 'your_index_name', 'apiKey': '' } </script> <script id="algolia__template" type="text/template"> <div class="algolia__result"> <a class="algolia__result-link" href="{{ url }}#algolia:{{ css_selector }}">{{{ _highlightResult.title.value }}}</a> {{#posted_at}} <div class="algolia__result-date">{{ posted_at_readable }}</div> {{/posted_at}} <div class="algolia__result-text">{{{ _highlightResult.content.value }}}</div> </script> <script id="algolia__template--no-results" type="text/template"> No results found. </script> <script src="//cdn.jsdelivr.net/jquery/2.1.4/jquery.min.js"></script> <script src="//cdn.jsdelivr.net/algoliasearch/3.6.0/algoliasearch.min.js"></script> <script src="//cdn.jsdelivr.net/algoliasearch.helper/2.1.0/algoliasearch.helper.min.js"></script> <script src="//cdn.jsdelivr.net/hogan.js/3.0.2/hogan.min.js"></script> <script src="//cdn.jsdelivr.net/momentjs/2.10.3/moment.min.js"></script> <script src="public/js/algolia.js"></script>
-
Adjust CDN.
Although Algolia makes use of the jQuery library stored in a CDN, you can use another CDN (such as Google’s) if you prefer.
-
Add dependencies and their versions in the Gemfile.lock file:
-
Specify the Jekyll plugin in the Gemfile file:
source 'https://rubygems.org' gem 'jekyll', '>=2.5.3' group :jekyll_plugins do gem 'algoliasearch-jekyll' end
.gitignore
-
Edit the project’s .gitignore file so the key is not uploaded to GitHub:
_algolia_api_key
NOTE: The leading underline character tells Jekyll to not convert it into HTML.
- Edit variables and their values in the project’s _config.yml file.
### Replace Site Icon #
TODO: ReplaceSiteIcon
index.html
-
Navigate down the folders to an index.html file and open it in a text editor.
NOTE: All content files are named index.html so visitors don’t have to type in the .html file extension. It is better for SEO (Search Engine Optimization) if folder names are used as links.
- Dashes are interpreted by search engines as spaces between words.
- Underlines are interpreted as compound words.
-
Press Ctrl+F to search for
<article class="post">
a HTML5 standard tag to designate content (and not navigation and other fluff).Text in the file replaces the tag:
{{ content }}
In the _includes folder of the Algolia template are the head.html, footer.html, and sidebar.html.
When a web page (index.html) is loaded by an internet browser at the client end,
contents of the <head>
are processed first.
The Algolia Jekyll theme defines that code in the head.html file.
That includes <link
statements to bring in JavaScript and CSS files.
sidebar.html
The sidebar.html file contains what is within the <div class="sidebar">
tag positioned to the left of content on every page.
The search field is in that file:
<input type="text" class="algolia__input js-algolia__input" autocomplete="off" name="query" placeholder="Search in this site..." />
TODO: Explain Notice there is no JavaScript “onClick” function here.
That’s because JavaScript functions have been invoked when the website was loaded to watch for changes in classes algolia__input and js-algolia__input.
footer.html
The footer.html file contains what goes before the </body>
tag at the bottom of every page.
The Algoria template also defines JavaScript variables and populates them with values from the _config.xml file:
JavaScript
The onLinkClick JavaScript function invoked is defined in the algolia.js file within the public/js folder.
-
onQueryChange
-
onResult
-
renderResults
-
getAnchorSelector
-
scrollPageToSelector
The above in turn reference functions in libraries pulled in from the internet:
Search Field CSS Formatting
It seems there are as many ways to store CSS in Jekyll sites as there are Jekyll sites.
Each option involves changes to CSS as well to suit your design tastes.
The Algoria theme keeps CSS and JavaScript within a folder named public. A separate algoria.css file contains styling for both the search box and search results.
Notice it is raw CSS, with no SASS processing.
Many Jekyll templates use SASS, which expands style codes in sass files to generate CSS used in websites.
Additional resources about SASS:
-
A popular SASS library is bourbon
The underline in the name means that the folder is not transferred into the _site folder.
Resources
- Nick Zadrozny is the co-founder of Bonsai.io.
More on front-end styling
This is one of several topics:
- UI Design Systems
- Text Editors
- Markdown text for GitHub from HTML
- gRPC (g___ Remote Procedure Call)
- Front-end UI creation options
- Docusaurus static website generator
- Static websites
- JAM Stack Website Project Plan
- Jekyll Site Development
- Website styles
- Website Styling
-
Protractor to automate testing of Angular and other web pages
- Email from website
- Search within Hyde format Jekyll websites
- Data Visualization using Tableau