smart-search-plugin v2.1.1
Smart Search Plugin for Docusaurus
A metadata-driven search plugin for Docusaurus 2.x that provides targeted, efficient search capabilities with an elegant, accessible interface. By leveraging metadata keywords, this plugin delivers precise search results while working seamlessly offline and in firewall-restricted environments.
š Try the live demo | š Read the full blog post
Support for Docusaurus 3.x is a work in progress. Stay tuned!
Why Smart Search?
The Smart Search Plugin reintroduces the proven concept of metadata keywords for documentation search while adding modern fuzzy search capabilities:
- šÆ Targeted Results: Content tagged with relevant metadata receives higher ranking
- š Fuzzy Search: Intelligent matching tolerates typos and partial matches
- šāāļø Offline Operation: Works behind firewalls without external API dependencies
- ā”ļø Local Testing: Test search functionality during development
- š± Modern Interface: Responsive design with full keyboard navigation
- āæļø Accessibility: ARIA-compliant with keyboard navigation and screen reader support
Installation
npm install smart-search-plugin
yarn add smart-search-plugin
Configuration
Add the plugin to your docusaurus.config.js
:
const path = require('path');
staticDirectories: ['static'], // Required for search index
plugins: [
path.resolve(__dirname, 'node_modules/smart-search-plugin')
],
presets: [
[
'@docusaurus/preset-classic',
{
docs: {
routeBasePath: '/', // Required
path: 'docs', // Required for the correct linking of topics
showLastUpdateTime: true, // Enables last update display
},
},
],
],
themeConfig: {
navbar: {
items: [
{
type: 'search',
position: 'right',
},
],
},
},
};
Document structure
Required directory structure
your-docusaurus-site/
āāā docs/ # Documentation root
ā āāā intro.md # Documentation files
ā āāā advanced/
ā āāā config.md
āāā static/ # Static assets directory
āāā docusaurus.config.js # Configuration file
Frontmatter configuration
Your markdown files can include these frontmatter fields for enhanced search functionality:
---
title: Document Title
description: A brief description that appears in search results
keywords: [search, docusaurus, plugin]
draft: false # Exclude from search when true
last_update: # Optional update tracking
date: 2024-03-20
author: John Doe
---
Content processing
Smart content indexing
The plugin processes your content with these features:
- Intelligent caching
- File-based caching system for faster builds
- Automatic detection of content changes
- Incremental rebuilding for modified files only
- Content normalization
- Consistent URL generation across platforms
- Special handling for index files
- Clean URL paths for improved SEO
- Automatic exclusions
Content automatically excluded from search:
- Root/welcome page (URL: '/')
- Draft documents
- Content in excluded folders (default: 'contributor-guide')
- Files with
draft: true
in frontmatter
Search index generation
The plugin creates two search index files:
/build/searchIndex.json
: Public search index/static/searchIndex.json
: Development index
User interface
Search component features
The search interface provides:
- Expandable search input
- Real-time results dropdown
- Keyboard navigation support
- Result highlighting
- Last update information display
- Mobile-friendly design
Search Implementation
Here's how the Smart Search Plugin appears in your Docusaurus navbar:
Inactive state
Activated state with results
The search functionality seamlessly integrates with your Docusaurus theme while maintaining the metadata-driven approach.
Keyboard shortcuts
The search interface supports full keyboard navigation:
/
orCtrl+K
: Focus search inputā
/ā
: Navigate through resultsEnter
: Go to selected resultEscape
: Clear search or close dropdownTab
: Navigate through interactive elements
Technical details
Dependencies
The plugin uses these key dependencies:
fuse.js
: Fuzzy search implementationantd
: UI components@ant-design/icons
: UI iconsgray-matter
: Frontmatter parsingunified
: Content processing
Browser Support
- Modern browsers (Chrome, Firefox, Safari, Edge)
- IE11 not supported
Contributing
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
License
MIT
Credits
Built with: