Socket
Socket
Sign inDemoInstall

svelte-algolia

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

svelte-algolia

Algolia plugin for Svelte


Version published
Weekly downloads
14
decreased by-53.33%
Maintainers
1
Weekly downloads
 
Created
Source

Banner

svelte-algolia   Test Status NPM version GitHub

This package was inspired by gatsby-plugin-algolia.

Usage

  1. Install with yarn or npm

    yarn add -D svelte-algolia
    
    npm i -D svelte-algolia
    
  2. Create an algoliaConfig object:

    import 'dotenv/config' // optional
    
    const algoliaConfig = {
      appId: process.env.algoliaAppId,
      apiKey: process.env.algoliaAdminKey,
      indices: [
        { name: `pokedex`, getData: pokemonDataLoader },
        { name: `hitchHikersGuide`, getData: guideGetter },
      ],
    }
    

    The getData function is expected to return an array of objects containing the data you wish to index (a product catalog, blog posts, documentation pages, pokémons or whatever). Each object in the data array should have a key named id or objectID for Algolia to recognize it and overwrite existing data where appropriate.

  3. Pass your config to indexAlgolia:

    import { indexAlgolia } from 'svelte-algolia'
    
    indexAlgolia(algoliaConfig)
    

    You can call this function wherever you'd like to update your indices. Typically, you would include this in every production build of your app.

Config Options

const defaultConfig = {
  verbosity: 1, // 0, 1 or 2 for no/some/lots of logging
  partialUpdates: false, // if true, figures out diffs between existing
  // items and new ones and only uploads changes, otherwise, completely
  // overwrites each index on every call to indexAlgolia()
  matchFields: [], // (only used when partialUpdates is true) keys of fields to
  // check for whether an item has changed; could e.g. be a timestamp, hash or
  // an ID that's updated every time the item has changed; if not provided, items
  // are checked for deep-equality to discover changes
  settings: {}, // an object of Algolia index settings that applies to all indices
  // see https://algolia.com/doc/api-reference/settings-api-parameters for available options
  // can be overridden for individual indices by passing a settings object as part of the indices array:
  // indices = [{ name: `pokedex`, ..., settings: { foo: `bar` }}],
}

As a rollup plugin

To use this package as part of a rollup build (e.g. in a Svelte or Sapper app), simply include it in your plugins array:

// rollup.config.js
import { indexAlgolia } from 'svelte-algolia'

const algoliaConfig = {
  // see above
}

// check if running in build or development mode
const dev = process.env.NODE_ENV === `development`

export default {
  input: './src/index.js',
  output: {
    file: './build/bundle.js',
    format: 'iife',
    name: 'bundle'
    plugins: [
      // to save Algolia indexing operations, you may want to only
      // update your indices when building your app for production
      !dev && indexAlgolia(algoliaConfig),
    ]
  }
}

Contribute

PRs are welcome but best open an issue first to discuss changes.

Keywords

FAQs

Package last updated on 05 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc