Skip to content

jackcarey/astro-lunr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⚠️ this integration isn't finished yet and I don't know when it will be. The code might still be useful for others developing similar functionality, so it'll stay up until I can get back to it.

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 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."
    }
]

Configuration

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.

Client-side

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published