hugo-lunr-ml
hugo-lunr-ml
Generate search indexes for your Hugo static site. Automatically creates ready-to-use lunr-index.json files that integrate seamlessly with lunr.js.
When to Use
Building a Hugo site with search functionality often means manually creating search indexes or writing custom scripts. For multilingual sites, this becomes even more complex. What if you could generate search indexes automatically, supporting multiple languages with a single command?
hugo-lunr-ml transforms your Hugo content into searchable indexes. Whether your site is multilingual or single-language, this tool generates the files you need for powerful client-side search powered by lunr.js.
What It Does
- Multilingual support - Generate search indexes for multiple languages
- Automatic generation - Scans your Hugo content and creates ready-to-use indexes
- lunr.js integration - Outputs files that work directly with lunr.js
- Customizable - Configure input paths, output paths, and default languages
- Simple workflow - One command generates everything you need
Why It Matters
Search shouldn't be an afterthought. When your content becomes instantly searchable with minimal setup, you create better experiences for your readers. Multilingual sites gain powerful search across all languages, and single-language sites get robust search capabilities without the complexity.
Perfect for Hugo site builders who want search functionality without the manual work, developers managing multilingual content, and anyone who believes great sites deserve great search.
Next.js Implementation Use Case
For Next.js applications with MDX content, consider using fuse.js with a custom build-time index generation script. Here's a pattern that adapts the concepts from hugo-lunr-ml to Next.js:
// scripts/generate-search-index.js
import fs from 'fs';
import path from 'path';
import { compile } from '@mdx-js/mdx';
import { serialize } from 'next-mdx-remote/serialize';
import Fuse from 'fuse.js';
const contentDir = './content';
const outputFile = './public/search-index.json';
async function extractTextFromMDX(filePath) {
const content = fs.readFileSync(filePath, 'utf-8');
// Extract frontmatter and body text
const { frontmatter, body } = await parseMDX(content);
return { frontmatter, body: stripMarkdown(body) };
}
function generateSearchIndex() {
const documents = [];
// Scan content directories and process MDX files
// Similar to hugo-lunr-ml but for Next.js structure
return documents;
}
generateSearchIndex();This approach provides:
- Build-time index generation - Search indexes created during build
- MDX support - Native processing of MDX content
- Multilingual ready - Easy extension for multiple locales
- Client-side search - Fast, privacy-focused search using Fuse.js
Links:
- π¦ NPM Package
- π GitHub Repository
- π Full Documentation
Platforms: npm