Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Quick Client-Side Search Functionality to Jekyll Sites #9716

Open
Lahoussine-Bouhmou opened this issue Nov 15, 2024 · 1 comment
Open
Labels

Comments

@Lahoussine-Bouhmou
Copy link

Summary:

It would be extremely beneficial for Jekyll users to have a built-in, simple, and fast client-side search functionality to easily search through their site’s posts, pages, and other content. The addition of a search feature would enhance the usability of Jekyll websites, particularly for larger sites where users need to find specific content quickly. This feature would not require server-side integration and could work entirely within the client’s browser, using an index generated at build time.

Motivation:

Currently, Jekyll does not include built-in search functionality. While there are third-party solutions, integrating a basic client-side search mechanism would streamline the experience for users who don’t need a full-fledged server-side search engine. This would be especially useful for documentation sites, blogs, and portfolios built with Jekyll, where users often need to quickly locate posts or pages based on keywords.

Proposed Solution:

I propose adding an optional client-side search feature that can be easily integrated into Jekyll sites. The solution would involve the following steps:

  1. Indexing content during the build process: Use Jekyll’s build system to generate a JSON file that contains all the important data from the site’s content (titles, URLs, and descriptions of posts and pages). This JSON file will serve as the search index.

  2. Client-Side Search Implementation: Integrate a lightweight JavaScript library such as Lunr.js to search through the indexed content on the client side. Lunr.js allows fast, full-text search and works entirely in the browser.

  3. Search Bar Integration: Add a search bar component to the site layout where users can type search queries. The search results will dynamically display relevant content without reloading the page.

  4. Customization: The feature should be configurable so users can choose which content is indexed (e.g., blog posts, pages, categories) and whether the search bar is enabled globally or only on certain pages.

Benefits:

  • Improved User Experience: Users will be able to find content quickly without having to rely on external search engines.
  • Client-Side Performance: Since the search happens entirely in the browser, there’s no need for server-side resources, which makes it a lightweight and fast solution.
  • Simplicity: The feature could be optional and easily added to existing Jekyll sites through a simple configuration setting.
  • Customization: The search index and functionality would be customizable, enabling Jekyll users to control which parts of their site are searchable.

Acceptance Criteria:

  • The feature should generate an index file (e.g., search.json) that includes essential data like post titles, URLs, and excerpts.
  • Users should be able to include a search bar on their site’s layout that queries this index and displays results.
  • The search should work entirely client-side, using a JavaScript library (e.g., Lunr.js) to perform the search.
  • The feature should include configuration options to control which content is indexed and whether the search bar is included in the site’s navigation.
  • The feature should be optional, and users should be able to enable or disable it through their site’s _config.yml file.
  • The solution should be lightweight and fast, providing a seamless experience for users browsing the site.

Example Usage:

  1. Enabling Search in _config.yml:
    search_enabled: true
  2. Customizing Indexing:
    search_content:
      - posts
      - pages

Additional Notes:

  • A possible integration with tools like Jekyll Search or Lunr.js could help jumpstart the development, but the goal would be to provide a built-in solution that is easy for users to enable with minimal setup.
@ashmaroli
Copy link
Member

Thank you for submitting a detailed feature request ticket, @Lahoussine-Bouhmou.

Pull requests complete with tests and documentation are welcome. Since, this functionality may have significant effect on build times, the submitted PR will have multiple rounds of reviews and profiling tests against sample large repos.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants