Integration for building LunrJS index for Astro websites. Index items include text content underneath each heading tag.
Your Astro site should be set up and there should be no existing file at /search_index.json
as it will be overwritten.
You must enable experimental integrations to use third-party integrations with Astro. After doing this, you can install this integration like any other:
npx astro add @jackcarey/astro-lunr
or
npm i @jackcarey/astro-lunr
Each entry in search_index.json
contains loc
, title
, and content
properties.
dist/some-path/index.html
//...
<h2 id="foo">Foo Heading</h2>
<p>The text underneath the foo heading.</p>
<h2 id="bar">Bar Heading</h2>
<p>The text underneath the bar heading.</p>
//...
search_index.json
[
{
"loc": "/some-path#foo",
"title": "Foo Heading",
"content": "The text underneath the foo heading."
},
{
"loc": "/some-path#bar",
"title": "Bar Heading",
"content": "The text underneath the bar heading."
}
]
There are four functions you can pass to configure the index. Each function must return a boolean for whether or not it is included in the search index.
- routeFilter - A regular JavaScript array filter that accepts Astro RouteData as input.
- resultFilter - A regular JavaScript array filter that accepts index items as input.
- headingFilter - Uses a Cheerio filter against each heading tag. The default filter ignores headings that appear inside
<header/>
or<nav/>
tags. - contentFilter - Uses a Cheerio filter against the content below each heading.
This package doesn't provide a component yet, so use the LunrJS documentation to integrate a search input into your site.