@jackcarey/astro-lunr
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

astro-lunr

Integration for building LunrJS index for Astro websites. Index items include text content underneath each heading tag.

Prerequisites

Your Astro site should be set up and there should be no existing file at /search_index.json as it will be overwritten.

Install

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

Usage

Index items

Each entry in search_index.json contains loc, title, and content properties.

dist/some-path/index.html

//...
<h2>Foo</h2>
<p>The text underneath the foo heading.</p>
<h2>Bar</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."
    }
]

Configuration

There are three 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.
  • contentFilter - Uses a Cheerio filter against the content below each heading.

Client-side

This package doesn't provide a component yet, so use the LunrJS documentation to integrate a search input into your site.

Package Sidebar

Install

npm i @jackcarey/astro-lunr

Weekly Downloads

1

Version

0.0.6

License

MIT

Unpacked Size

3.47 kB

Total Files

2

Last publish

Collaborators

  • jackcarey