Giter VIP home page Giter VIP logo

contentful-to-algolia's Introduction

Transmit data from Contentful to Algolia

The application syncs content between Contentful and Algolia. You can configure the service to run with Drafts (Preview API) from Contentful and put it in different indexes in Algolia. The prefix of each index can be configured.

Install the module

npm install --save contentful-to-algolia

Documentation

The main method of Sync:

sync(
  Array <types>,
  String <indexName>,
  [Function <callback>],
  [String <entryId>],
  [Function <manipulateSingle>]
)

Sync multiple content types from Contentful to Algolia

Usage

// Require module
const ContentfulToAlgolia = require('contentful-to-algolia');

// Generate new instance
const Sync = new ContentfulToAlgolia(Object <config>);

// Sync data
Sync.sync(
  String <type>,
  String <indexName>,
  [Function <callback>],
  [String <entryId>],
  [Function <manipulateSingle>]
);

Example config

You can find a sample configuration in config.sample.js.

Todo

  • Remove elements which are not used anymore
  • Use Contentful's Syncronisation API
  • Tests

License

This project is under MIT license, 2017, ⓒ Hans Christian Reinl. Read more in LICENSE.

contentful-to-algolia's People

Contributors

christineywang avatar dependabot[bot] avatar drublic avatar thetoine avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

contentful-to-algolia's Issues

Circular reference creates stack overflow error

Situation: my space has articles and posts. Article A has a multiple reference field with "related posts" that includes Post B. Post B has a multiple reference field with "related articles", that includes Article A.

If I run a build at which I try to sync my items with Algolia, the following happens.

Error message:
RangeError: Maximum call stack size exceeded at Contentful._cleanMore (/Users/Sander/GitHub/gatsby/blog/node_modules/contentful-to-algolia/lib/Contentful.js:171:15)

Bug sits in _getLocalForNestedFields. If I comment out lines 134 to 151 and simply delete the circular array (like delete entry[key]) - the error is gone.

Issue with manipulateSingle function

Hello!

I am able to successfully use the contentful-to-algolia integration to import Contentful data into Algolia without any entry manipulation. Now, I would like to test changing the shape of the JSON so that entries are only indexed with specified properties.

My question is related to using the manipulateSingle function. The sync method works when I specify the content type ID, index name, and callback function parameters:

Sync.sync(
  <contentTypeID>,
  <indexName>,
  <callback function>
);

The last two parameters are what I am having issues with. Do I need to specify the <entryId> parameter? I don't want to so I have been testing out values such as undefined and false but I get the error that a string is expected. What I care about is being able to run the manipulateSingle function. If I don't put anything in the <entryID> parameter and use this:

Sync.sync(
  <contentTypeID>,
  <indexName>,
  <callback function>,
  <manipulateSingle>
);

The sync works, entries are imported, and I don't get errors in the console. However, the manipulateSingle function is ignored and my entries are not indexed with their new shape.

What am I doing wrong?

Here is what I am trying to get to work:

const formatter = ({
  id,
  createdAt,
  locale,
  productName,
  slug,
  productDescription,
  tags,
  contentType
}) => ({
  id,
  locale,
  objectID: id,
  createdAt,
  productName,
  slug,
  productDescription,
  tags,
  contentType
});


Sync.sync(
  '2PqfXUJwE8qSYKuM0U6w8M',
  'blog',
  function(algolia_response) {
    const response = algolia_response;
    console.log('res', JSON.stringify(algolia_response));
    console.log('number of indexed entries:', algolia_response.length);
  },
  // undefined,
  formatter
);

Thanks so much!

Issue with Asset objects being processed in _cleanEntry

👋 I'm using contentful-to-algolia on a project and I had a question about this commit. In _cleanEntry on line 97 it will access entry.sys.contentType, but the array of entries being sent to this code includes objects representing assets, which do not include the contentType key.

I'm just curious which API you're using to build this library. I ran into the above error with the Delivery API, and I know some of Contentful's APIs deliver data in different formats.

Thanks for making this library though, it's been a big help.

Add support for more than 100 entries

I have a content type with over 1000 entries, but the library currently only processes 100 entries. This feature could be implemented using the skip and limit parameters. Thoughts?

Filtering entries

Is there any way to filter out entries based on their content?
Looks like returning null from manipulateSingle does not work.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.