🚀 A (still experimental) Lyra integration for Astro

Overview

Lyra's Astro Plugin

This package is a (still experimental) Lyra integration for Astro.

Usage

Configuring the Astro integration

// In `astro.config.mjs`
import lyra from '@lyrasearch/plugin-astro'

// https://astro.build/config
export default defineConfig({
  integrations: [
    lyra({
      // We can generate more than one DB, with different configurations
      mydb: {
        // Required. Only pages matching this path regex will be indexed
        pathMatcher: /blog\/[0-9]{4}\/[0-9]{2}\/[0-9]{2}\/.+$/,

        // Optional. 'english' by default
        language: 'spanish',

        // Optional. ['body'] by default. Use it to constraint what is used to
        // index a page.
        contentSelectors: ['h1', 'main'],
      },
    }),
  ],
});

When running the astro build command, a new DB file will be persisted in the dist/assets directory. For the particular case of this example, it will be saved in the file dist/assets/lyraDB_mydb.json.

Using generated DBs in your pages

To use the generated DBs in your pages, you can include a script in your <head> section, as the following one:

<head>
  <!-- Other stuff -->
  <script>
    // Astro will do the job of bundling everything for you
    import { getLyraDB, search } from "@lyrasearch/plugin-astro/clientside"

    // We load the DB that we generated at build time, this is an asynchronous
    // operation, so we must either await, or rely on `.then` calls.
    const db = await getLyraDB('mydb')

    // Now we can search inside our DB. Of course, feel free to use it in more
    // interesting ways.
    console.log('Search Results')
    console.log(search(db, { term: 'mySearchTerm' }))
  </script>
</head>

NOTE: For now, this plugin only supports readonly DBs. This might change in the future if there's demand for it.

Comments
  • ignore case when doing route and path matching

    ignore case when doing route and path matching

    I am working on an astro internal site and wanted to get Lyra a go for indexing the content of the site.

    We have the following folder structure

    docs
    -> components
    --> MyComponent
    ----> index.md
    

    The path matcher was not working because the path matching is case sensitive.

    https://github.com/LyraSearch/plugin-astro/blob/4f209680cf7df957b65618e20c95487ffe64c71c/src/index.ts#L65

    Possible solution

    r.route.replace(/(^\/|\/$)/g, '').toLowerCase() === pathname.replace(/(^\/|\/$)/g, '').toLowerCase()
    

    Let me know if I can create a pull request.

    Cheers

    new feature 
    opened by david10sing 5
  • Prepare 0.0.2 release

    Prepare 0.0.2 release

    There aren't many new things yet, as I didn't had time these past days, but I think it's worth releasing a new version that is compatible with new Lyra & Astro versions.

    Fixes #20

    opened by castarco 3
  • feat: add case insensitive route and path comparison

    feat: add case insensitive route and path comparison

    Description The astro plugin is doing a case sensitive match on route and file paths.

    As mentioned by @castarco this makes sense. However, the generated paths from astro's build makes everything lowercase.

    This PR is to implement case insensitive matching on the files generated by astro's build and the folder structure being parsed.

    Fixes issue https://github.com/LyraSearch/plugin-astro/issues/28

    new feature 
    opened by david10sing 1
  • `dist/esm` directory is not included in published package

    `dist/esm` directory is not included in published package

    It seems that because of the problems in the build scripts on Mac, the dist/esm directory was not included in the published package. This is problematic when running astro build command.

    bug 
    opened by castarco 1
  • directory is not available when running in a minimal Astro setup

    directory is not available when running in a minimal Astro setup

    When running in a minimal Astro setup, no other integration/plugin takes care of creating the assets directory at build time. The plugin was assuming it would always be there, but that's not the case.

    bug 
    opened by castarco 0
  • pathname & route matching is broken under certain Astro configurations.

    pathname & route matching is broken under certain Astro configurations.

    Because of how pages' pathname and routes arrive to the hook function, it can happen (depending on the configuration, so not always) that one is of the form /some/path, and the other is like some/path/.

    They refer to slightly different concepts, and this shouldn't pose a problem in most scenarios, but we need to match them while generating our indices (The current code only works well when this doesn't happen).

    bug compatibility 
    opened by castarco 0
  • Fix 2 minor bugs & add first integration tests

    Fix 2 minor bugs & add first integration tests

    This PR fixes two previously undocumented bugs:

    • Fixes #22 .
    • Fixes #23 .

    In addition, there's a set of new "integration" tests that try to verify that the library can be packed, installed and used as intended.

    bug ci/cd 
    opened by castarco 0
  • Build on Macos is broken

    Build on Macos is broken

    The build scripts have been only properly tested on Linux. It turns out that sed behaves in a slightly different way when executed in Mac, probably because of differences between GNU & BSD flavours.

    Blocks #1 .

    bug compatibility devex 
    opened by castarco 0
  • Allow Astro pages to import script to load DBs registry/getter

    Allow Astro pages to import script to load DBs registry/getter

    For now, only DBs generation has been implemented. We also need to implement the client-side part of this plugin, to make it possible for websites to load the generated DBs and use them on the browser/client side.

    new feature 
    opened by castarco 0
  • fix: #28 normalise generated file paths

    fix: #28 normalise generated file paths

    Description This is a PR to fix broken build on Windows which was being caused due to a leading slash in the file pathname.

    Fixes LyraSearch/plugin-astro#29

    Todo

    • [ ] fix tests so they can run on both windows and unix machines
    opened by david10sing 1
  • Implement yarn workspaces

    Implement yarn workspaces

    @david10sing Thank you for showing interest on this.

    My idea was to create a monorepo, but starting "very small" (just with the very basic features of yarn, and only jumping to more sophisticated setups later).

    As you suggested, having a packages directory is a good idea. I would move most code we already have into a sub-directory of packages, perhaps just plugin-astro, and I would create sibling directories for each one of the framework integrations (React, Solid, ...), something like @lyrasearch/plugin-astro-solidjs for the package name (and just plugin-astro-solidjs for the directory name).

    My idea is that each one of these packages would have @lyrasearch/plugin-astro as a dependency, to ensure that users only have to care about installing a single dependency.

    Regarding previews, honestly... I didn't think at all about that. I'm open to suggestions.

    Originally posted by @castarco in https://github.com/LyraSearch/plugin-astro/issues/12#issuecomment-1364557846

    • [ ] implement yarn workspaces
    opened by david10sing 0
  • chore: add eslint plugin prettier and rule to prevent one var

    chore: add eslint plugin prettier and rule to prevent one var

    Description This is a PR to make eslint and prettier work better together.

    The goal is to have prettier and eslint show errors and in the developer's editor.

    This is following the eslint-plugin-prettier README to setup the plugin.

    How to test

    1. In your IDE (I use vscode), try to chain create const like so const foo = 'bar', baz: 'foo'
    2. Confirm you see an eslint message like the following

    Screenshot from 2022-12-24 07-34-07

    1. After saving your file, confirm it fixes (if you have this enabled in your IDE) like so

    Screenshot from 2022-12-24 07-35-04

    devex 
    opened by david10sing 2
  • Configuration out dir  is broken on windows

    Configuration out dir is broken on windows "\C:\"

    When I started astro build on windows, in the astro:build:done hook, the property config.outDir.pathname start with \C:\Users\... The \ before C:\ brokes all build process with the following error:

    invalid argument, mkdir '\C:\Users\s.golinucci\Documents\Dev\formazione\astro-test\dist\assets'

    https://github.com/LyraSearch/plugin-astro/blob/4f209680cf7df957b65618e20c95487ffe64c71c/src/index.ts#L110-L114

    I fixed in my node modules removing first \ and I noted the same problem with generatedFilePath variable:

    https://github.com/LyraSearch/plugin-astro/blob/4f209680cf7df957b65618e20c95487ffe64c71c/src/index.ts#L78-L81

    I also fixed generatedFilePath and all build process works correctly.

    bug compatibility 
    opened by SimOneGollo 3
  • feat: log generation time

    feat: log generation time

    Add a log line to Astro's build output, so we can know how much time it takes to generate & persist Lyra indices.

    Signed-off-by: Andres Correa Casablanca [email protected]

    new feature devex 
    opened by castarco 0
  • Node16/NodeNext rough edges - support for `./clientside` imports

    Node16/NodeNext rough edges - support for `./clientside` imports

    • On "normal" NPM + TS projects, it is necessary to set moduleResolution to Node16 or NodeNext (in tsconfig.json file) if we want to import from @lyrasearch/plugin-astro/clientside.
    • In Astro projects, VSCode will keep complaining about invalid imports for @lyrasearch/plugin-astro/clientside no matter what we specify for the moduleResolution option. But:
      • It will build correctly if it's set to node
      • It will present some problems if we set it to Node16 or NodeNext.

    I don't expect this issue to be solvable from our side, at least not soon, as it seems to depend more on Astro improving its support for ESM and new TS resolution modes. But it's worth taking note, in case anyone else has to fight against the same problems.

    devex 
    opened by castarco 0
Releases(0.0.2-alpha.0)
  • 0.0.2-alpha.0(Sep 10, 2022)

    What's Changed

    • fix: fixes release scripts by @micheleriva in https://github.com/LyraSearch/plugin-astro/pull/15
    • chore: switch @nearform/lyra -> @lyrasearch/lyra by @castarco in https://github.com/LyraSearch/plugin-astro/pull/18
    • Enable CI pipelines by @castarco in https://github.com/LyraSearch/plugin-astro/pull/17
    • Fix macos build by @castarco in https://github.com/LyraSearch/plugin-astro/pull/16
    • Fix 2 minor bugs & add first integration tests by @castarco in https://github.com/LyraSearch/plugin-astro/pull/21
    • Prepare 0.0.2 release by @castarco in https://github.com/LyraSearch/plugin-astro/pull/19

    New Contributors

    • @micheleriva made their first contribution in https://github.com/LyraSearch/plugin-astro/pull/15

    Full Changelog: https://github.com/LyraSearch/plugin-astro/compare/0.0.1-alpha.0...0.0.2-alpha.0

    Source code(tar.gz)
    Source code(zip)
  • 0.0.1-alpha.0(Aug 19, 2022)

Owner
Lyra
The edge-ready full-text search engine
Lyra
🦔 AstroJS GoogleChromeLabs critters integration. Inline your critical CSS with Astro.

astro-critters ?? This Astro integration brings critters to your Astro project. Critters is a plugin that inlines your app's critical CSS and lazy-loa

Nikola Hristov 33 Dec 11, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
💾 Data persistence plugin for Lyra

Data Persistence Plugin This plugin aims to provide data persistence capabilities to Lyra. Runtime Status Node.js ✅ available Bun ✅ available V8 isola

Lyra 29 Dec 20, 2022
Create a Lyra database from anywhere.

?? ☄️ ️ Impact Create a Lyra database from anywhere. Installation You can install Lyra using npm, yarn, pnpm: npm i @mateonunez/lyra-impact yarn add @

Mateo Nunez 10 Dec 19, 2022
Connect Web Integration illustrates the integration of Connect-Web in various JS frameworks and tooling

Connect Web Integration Connect Web Integration is a repository of example projects using Connect-Web with various JS frameworks and tooling. It provi

Buf 43 Dec 29, 2022
An api named Crypto Versus, a multiplayer versus hacking simulator. Project still in the making!

Crypto Versus A Multiplayer Versus Hacking Simulation Inspired by the Steam game Bitburner Table of content Possible ouputs for all endpoints routes /

null 3 Jan 29, 2022
Blobernize your pictures with this all-new tool! Still under development, but it works for now.

Still under development, but in a usable state image-blobernizer A very simple image-blobernizer made for the webbrowser using p5.js Live demo Require

Sen van der Heide 3 Mar 23, 2022
Kasada's p.js partially deobfuscated, still has VM logic

Kasada's p.js Deobfuscated The script was obfuscated by replacing most strings with a function to grab the string from an array and decode it. Ex: _0x

null 11 Nov 9, 2022
Vision is a complete project manager where you can colaborate with your team. Everything is still in development phase.

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

Nikko Abucejo 4 Jun 4, 2022
MerLoc is a live AWS Lambda function development and debugging tool. MerLoc allows you to run AWS Lambda functions on your local while they are still part of a flow in the AWS cloud remote.

MerLoc MerLoc is a live AWS Lambda function development and debugging tool. MerLoc allows you to run AWS Lambda functions on your local while they are

Thundra 165 Dec 21, 2022
This blog is still under development! I present a project scope for science articles, it can now be used in production! But there are some details that need to be put up front.

Science-Blog ?? Attention! This blog is still under development! I present a project scope for science articles, it can now be used in production! But

Raissadev 2 Sep 19, 2022
Fitness Platform with authentication and more (still in development) 🏋️‍♂️🏋️

LB Fitness readme Fitness platform with authentication containing workout plans, diet and blogs. Explore the docs » View Demo Table of Contents About

Lucas Bendix Jolibois 10 Dec 19, 2022
A tiny script and component intended to be used with Astro for generating images with eleventy-img.

Astro + eleventy-img A tiny script and component intended to be used with Astro for generating images with eleventy-img. It also supports creating blu

Erika 36 Dec 16, 2022
Astro 1.0 Hackathon submission

title published description tags cover_image Trying out Astro SSR & Astro 1.0 Hackaton false astro, ssr, webcomponents, hackathon https://imgur.com/lV

Pascal Schilp 26 Jan 2, 2023
Make an Astro site with content from Notion (and more)

Astronotion ⚠️ It is strongly recommended to upgrade to 0.0.7 (what has been fixed?) npm install -D astronotion@latest (or other package managers' equ

Eka 14 Dec 19, 2022
Auto-import components in Astro projects

Astro Auto Import ?? Looking for the main package? Jump to astro-auto-import → ?? Project Structure This project uses workspaces to develop a single p

Chris Swithinbank 22 Dec 30, 2022