npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@webcontext/contentful

v0.1.17

Published

For getting website entries from Contentful CMS

Downloads

631

Readme

Documentation Guide: Running the Contentful API for Webcontext Users

This guide provides instructions on how to install, use, and run the @webcontext/contentful package, which provides a convenient way to fetch data from the Contentful API for Webcontext users.

1. Installation

To get started, install the package using Yarn. In your project directory, run the following command:

yarn add "@webcontext/contentful"

2. Usage

Once the package is installed, you can use it to fetch data from Contentful. Here’s how to use the contentfulDelivery function.

2.1 Basic Usage

In your code, import the contentfulDelivery function from the package:

import { contentfulDelivery } from '@webcontext/contentful';

2.2 Fetching Data by Predefined Query (From File)

If you have a predefined query in a local file, you can use it as follows:

// Fetch data using a predefined query (e.g., 'copy-club') from a local file
const data = await contentfulDelivery({
  query: 'copy-club', // Name of the predefined query
  fromFile: true, // Indicates the query is from a local file
  fnSring: 'getEntries', // Optional function, defaults to 'getEntries'
});
console.log(data);

In this example, the query copy-club refers to a predefined query stored locally. The second property, fromFile: true, ensures the function reads from a file, while fnSring specifies the function to call (optional and defaults to getEntries).

2.3 Fetching Data with a Custom Query

For more flexible data retrieval, you can provide a custom query object:

const query = {
  query: {
    content_type: 'category', // The content type to retrieve, mandatory
    select: 'fields.name', // Optional: Specify fields to select
  },
  fromFile: false, // Indicates it's a custom query, not from a file
  fnSring: 'getEntries', // Optional, defaults to 'getEntries'
};

const data = await contentfulDelivery(query);
console.log(data);

In this example, a custom query is sent directly to the Contentful API, retrieving only the fields specified in the query.

3. Predefined Queries

The current predefined query list includes:

  • copy-club

You can use these predefined queries by passing the query name in the query field and setting fromFile to true.

4. Examples

Example 1: Using a Predefined Query (From File)

import { contentfulDelivery } from '@webcontext/contentful';

const data = await contentfulDelivery({
  query: 'copy-club',
  fromFile: true,
});
console.log(data);

Example 2: Using a Custom Query

import { contentfulDelivery } from '@webcontext/contentful';

const query = {
  query: {
    content_type: 'category',
    select: 'fields.name', // Optional field selector
  },
  fromFile: false, // Indicates custom query
  fnSring: 'getEntries', // Optional, defaults to 'getEntries'
};

const data = await contentfulDelivery(query);
console.log(data);

5. Conclusion

The @webcontext/contentful package simplifies interaction with the Contentful Delivery API. You can either use predefined queries stored locally or construct custom queries for flexible data retrieval from Contentful. Make sure your queries adhere to (https://www.contentful.com/developers/docs/references/content-delivery-api/)[Contentful's API documentation].