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

gatsby-source-bcms

v3.0.5

Published

Implementation of the @becomes/cms-most for Gatsby framework.

Downloads

8

Readme

Gatsby plugin for BCMS

This is a Gatsby source plugin for the BCMS.

Getting started

Best way would be to create a new project using BCMS CLI by running bcms --website create, but if you want to add the plugin to an existing project, you will need to follow next steps.

  • Install the plugin and its dependencies by running: npm i -D gatsby-source-bcms @becomes/cms-most @becomes/cms-client,
  • In gatsby-config.js add the plugin:
import {createBcmsMostConfig} from '@becomes/cms-most';

...

plugins: [
  ...

  {
    resolve: 'gatsby-source-bcms',
    options: createBcmsMostConfig({
      cms: {
        origin: process.env.BCMS_API_ORIGIN || 'https://becomes-starter-projects.yourbcms.com',
        key: {
          id: process.env.BCMS_API_KEY || '629dcd4dbcf5017354af6fe8',
          secret: process.env.BCMS_API_KEY_SECRET || '7a3c5899f211c2d988770f7561330ed8b0a4b2b5481acc2855bb720729367896'
        }
      },
      media: {
        download: false
      }
    }),
  }
]
  • If you do not add environment variables for your BCMS, as you can see, publicly available BCMS will be used.

Getting the BCMS data

There are 2 main way in which you can get data on Gatsby page. First is using Gatsby GraphQL and other is using Gatsby Node and BCMS Most.

GraphQL Query

Please have in mind that this is only an example and that you cannot just copy and paste it. This is because your BCMS might not contain data same as in this example.

pages/example.tsx

import { graphql } from 'gatsby';
import React, { FC } from 'react';
/**
 * This types are autogenerated by the BCMS Most. Have
 * in mind that you might not have them in your BCMS.
 */
import type { PagesEntry } from '../../bcms/types-ts';

interface Ctx {
  data: {
    page: {
      bcms: PagesEntry;
    };
  };
}

const Example: FC<Ctx> = ({ data }) => {
  return (
    <pre>
      <code>{JSON.stringify(data.page.bcms, null, '  ')}</code>
    </pre>
  );
};

export default Example;

export const query = graphql`
  query {
    page: bcmsPages(bcms: { meta: { en: { slug: { eq: "example" } } } }) {
      bcms {
        content {
          en {
            value
            type
            name
            isValueObject
            attrs {
              level
            }
          }
        }
        createdAt
        userId
        updatedAt
        templateId
        status
        meta {
          en {
            title
            slug
            cover_image {
              _id
              alt_text
              width
              src
              name
              height
              caption
            }
          }
        }
      }
    }
  }
`;

BCMS Most

Please have in mind that this is only an example and that you cannot just copy and paste it. This is because your BCMS might not contain data same as in this example.

templates/example.tsx

import React, { FC } from 'react';
/**
 * This types are autogenerated by the BCMS Most. Have
 * in mind that you might not have them in your BCMS.
 */
import { PagesEntry } from '../../bcms/types-ts';

interface Props {
  pageContext: {
    page: PagesEntry;
  };
}

const Example: FC<Props> = (props) => {
  const ctx = props.pageContext;
  return (
    <pre>
      <code>{JSON.stringify(ctx.page, null, '  ')}</code>
    </pre>
  );
};

export default Example;

gatsby-node.ts

import * as path from 'path';
import { CreatePagesArgs } from 'gatsby';
import { getBcmsMost } from 'gatsby-source-bcms';

export const createPages = async (data: CreatePagesArgs) => {
  const most = getBcmsMost();
  const {
    actions: { createPage },
  } = data;

  const examplePageData = await most.content.entry.findOne(
    'pages',
    async (item) => item.meta.en.slug === 'example',
  );
  createPage({
    component: path.resolve('src/templates/example.tsx'),
    path: '/example',
    context: {
      page: examplePageData,
    },
  });
};