Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jackcarey/astro-lunr
https://github.com/jackcarey/astro-lunr
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/jackcarey/astro-lunr
- Owner: jackcarey
- Created: 2022-08-21T12:45:09.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-04-03T18:47:37.000Z (9 months ago)
- Last Synced: 2024-04-25T20:55:45.588Z (9 months ago)
- Language: TypeScript
- Size: 1.38 MB
- Stars: 10
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- my-awesome-astro - astro-lunr - Astro integration for [Lunr](https://github.com/siverv/astro-lunr) search (What Do I Use... / If I want to add the ability to search?)
README
⚠️ 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.
- [Astro](https://astro.build/)
- [Lunr](https://lunrjs.com/)## 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](https://docs.astro.build/en/guides/integrations-guide/#finding-more-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*
```
//...Foo Heading
The text underneath the foo heading.
Bar Heading
The text underneath the bar heading.
//...
```*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](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) that accepts [Astro RouteData](https://docs.astro.build/en/reference/integrations-reference/#routes-option) as input.
- **resultFilter** - A regular JavaScript array [filter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) that accepts index items as input.
- **headingFilter** - Uses a [Cheerio filter](https://cheerio.js.org/classes/Cheerio.html#filter) against each heading tag. The default filter ignores headings that appear inside `` or `` tags.
- **contentFilter** - Uses a [Cheerio filter](https://cheerio.js.org/classes/Cheerio.html#filter) against the content below each heading.### Client-side
This package doesn't provide a component yet, so use the [LunrJS documentation](https://lunrjs.com/guides/getting_started.html) to integrate a search input into your site.