How to Make GitHub Pages Searchable: A Step-by-Step Guide
Using GitHub Pages for your personal or project website is a great way to establish an online presence. However, by default, GitHub Pages sites are not searchable. To make your GitHub Pages site searchable, you'll need to implement a search function. One of the most popular options is using Lunr.js, a tiny, powerful, and easy-to-use full-text search library.
In this guide, we'll walk through the process of adding Lunr.js to your GitHub Pages site and creating a simple search box and results page. This will make your site more user-friendly and boost its SEO by improving discoverability.
Setting up Lunr.js for GitHub Pages
Before you begin, ensure you have a GitHub Pages site set up. If you don't, you can follow GitHub's guide to create one.
Once your site is ready, we'll start by including Lunr.js in our project. We'll use the version hosted on a CDN to keep our project lightweight.
Including Lunr.js in your Project
In your project's main HTML file (usually `index.html`), add the following script tag just before the closing `` tag: