How to use contentful - 10 common examples

To help you get started, we’ve selected a few contentful examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github contentful-userland / contentful-wizard / src / init.ts View on Github external
key: string;
  spaceId: string;
  preview?: boolean;
  entryTitle?: IEntryTitle;
  style?: IStyles;
}) {
  if (!isBrowser()) {
    return {
      // tslint:disable-next-line no-empty
      update: () => {},
      // tslint:disable-next-line no-empty
      destroy: () => {}
    };
  }

  clients[spaceId] = createClient({
    // This is the space ID. A space is like a project folder in Contentful terms
    space: spaceId,
    // This is the access token for this space. Normally you get both ID and the token in the Contentful web app
    accessToken: key,
    // no additional requests
    resolveLinks: false,
    host: preview ? "preview.contentful.com" : undefined
  });

  const mergedStyle = mergeStyle(style);

  setStyle({ spaceId, style: mergedStyle });

  let cleanup: Function | null = attachHandlers({
    spaceId,
    entryTitle,
github contentful / contentful-metalsmith / lib / processor.js View on Github external
function getContentfulClient (accessToken, spaceId, host) {
  if (!clients[spaceId]) {
    clients[spaceId] = contentful.createClient({
      space: spaceId,
      accessToken,
      host
    })
  }

  return clients[spaceId]
}
github contentful-labs / product-catalogue-web.ts / src / app / contentful.service.ts View on Github external
_createClient() {
    this.cdaClient = createClient({
      space: this.config.space,
      accessToken: this.config.accessToken
    });
  }
}
github gridsome / gridsome / packages / source-contentful / index.js View on Github external
constructor (api, options) {
    this.options = options
    this.typesIndex = {}

    this.client = contentful.createClient({
      accessToken: options.accessToken,
      environment: options.environment,
      space: options.space,
      host: options.host
    })

    api.loadSource(async store => {
      await this.getContentTypes(store)
      await this.getAssets(store)
      await this.getEntries(store)
    })
  }
github EmaSuriano / gatsby-starter-mate / gatsby-config.js View on Github external
const contentful = require('contentful');
const manifestConfig = require('./manifest-config');
require('dotenv').config();

const { ACCESS_TOKEN, SPACE_ID, ANALYTICS_ID, DETERMINISTIC } = process.env;

const client = contentful.createClient({
  space: SPACE_ID,
  accessToken: ACCESS_TOKEN,
});

const getAboutEntry = entry => entry.sys.contentType.sys.id === 'about';

const plugins = [
  'gatsby-plugin-react-helmet',
  {
    resolve: 'gatsby-plugin-web-font-loader',
    options: {
      google: {
        families: ['Cabin', 'Open Sans'],
      },
    },
  },
github jepser / site-contentful / transport / contentful.js View on Github external
const { createClient } = require('contentful')

const contentClient = createClient({
  space: `${process.env.CONTENTFUL_SPACE_ID}`,
  accessToken: `${process.env.CONTENTFUL_TOKEN}`,
  host: process.env.CONTENTFUL_API_BASE_URL || null
})

module.exports = contentClient
github MehediH / ASTROTHUNDER / src / screens / ProjectScreen.js View on Github external
import React, { Component } from 'react'
import { Link } from 'react-router-dom';
import { generateBG } from '../utils/bgAnim.js';
import {Helmet} from "react-helmet";
import Markdown from 'markdown-to-jsx';

import * as contentful from 'contentful';

var client = contentful.createClient({
    space: process.env.REACT_APP_BLOG_SPACE,
    accessToken: process.env.REACT_APP_BLOG_ACCESS
})


export default class ProjectScreen extends Component {
    constructor(props){
        super(props)

        this.state = {
            project: [],
            notFound: false,
            gridSizeX: 0,
            gridSizeY: 0
        }
github keenethics / keenethics / lib / contentful.js View on Github external
export function getTagsAndCategories() {
  const client = createClient({
    space: SPACE_ID,
    accessToken: ACCESS_TOKEN,
  });

  return client.getEntries({
    content_type: 'post',
    select: 'fields.category,fields.tags',
  });
}
github redbadger / pride-london-app / src / integrations / cms.js View on Github external
export type SavedData = {
  entries: CmsEntry[],
  assets: Asset[],
  syncToken: string,
  updated: boolean
};

type SyncOpts = {
  initial: boolean,
  nextSyncToken?: string
};
type Client = {
  sync: SyncOpts => Promise
};

const client: Client = createClient({
  space: Config.CONTENTFUL_SPACE_ID,
  accessToken: Config.CONTENTFUL_API_KEY
});

export const getCmsData = async (
  loadCmsDataFn: typeof loadCmsData = loadCmsData,
  updateCmsDataFn: typeof updateCmsData = updateCmsData
): Promise => {
  const localCmsData = await loadCmsDataFn();
  const hasLocalCmsData = !!localCmsData;

  if (hasLocalCmsData) {
    return { ...localCmsData, updated: false };
  }

  return updateCmsDataFn();
github redbadger / pride-london-app / src / integrations / cms.js View on Github external
};
type SyncOpts = {
  initial: boolean,
  nextSyncToken?: string
};
type Client = {
  sync: SyncOpts => Promise
};

type UpdateEvents = () => Promise;
type GetEvents = (
  loadEvents?: loadEvents,
  updateEvents?: updateEvents
) => Promise;

const client: Client = createClient({
  space: Config.CONTENTFUL_SPACE_ID,
  accessToken: Config.CONTENTFUL_API_KEY
});

export const getEvents: GetEvents = async (
  loadEventsFn = loadEvents,
  updateEventsFn = updateEvents
) => {
  const localEventsData = await loadEventsFn();
  const hasLocalEventsData =
    !!localEventsData && localEventsData.events.length > 0;

  if (hasLocalEventsData) {
    return localEventsData.events;
  }

contentful

Client for Contentful's Content Delivery API

MIT
Latest version published 1 day ago

Package Health Score

92 / 100
Full package analysis