2.0.18 • Published 17 days ago

gatsby-source-newt v2.0.18

Weekly downloads
-
License
MIT
Repository
github
Last release
17 days ago

gatsby-source-newt

Install

Install the package with:

npm install gatsby-source-newt

# or

yarn add gatsby-source-newt

Basic Usage

gatsby-config.js

You need to declare the plugin use and its options in gatsby-config.js

module.exports = {
  plugins: [
    {
      resolve: 'gatsby-source-newt',
      options: {
        spaceUid: 'YOUR_SPACE_UID',
        token: 'YOUR_API_TOKEN',
        appUid: 'YOUR_APP_UID',
        models: [{
          uid: 'YOUR_MODEL_UID_1',
        }],
      },
    },
  ],
};

// If you want to source from multiple spaces or multiple apps, add another configuration.
module.exports = {
  plugins: [
    {
      resolve: 'gatsby-source-newt',
      options: {
        spaceUid: 'YOUR_SPACE_UID_1',
        token: 'YOUR_CDN_API_TOKEN_1',
        appUid: 'YOUR_APP_UID_1',
        models: [{
          uid: 'YOUR_MODEL_UID_1',
        }],
      },
    },
    {
      resolve: 'gatsby-source-newt',
      options: {
        spaceUid: 'YOUR_SPACE_UID_2',
        token: 'YOUR_CDN_API_TOKEN_2',
        appUid: 'YOUR_APP_UID_2',
        models: [{
          uid: 'YOUR_MODEL_UID_2',
        }],
      },
    },
  ],
};

Options

{
  /**
   * `spaceUid` is your space uid.
   *
   * Required
   * Type: String
   **/
  spaceUid: 'YOUR_SPACE_UID',

  /**
   * `token` is an authentication token used for the API.
   * If you use the CDN API, enter the CDN API token; if you use the Newt API, enter the Newt API token.
   *
   * Required
   * Type: String
   **/
  token: 'YOUR_API_TOKEN',

  /**
   * `appUid` is your app uid.
   *
   * Required
   * Type: String
   **/
  appUid: 'blog',

  /**
   * `models` is an array of information about the models you want to source.
   *
   * Required.
   * Type: Array
   **/
  models: [{
    /**
     * `uid` is your model uid.
     *
     * Required
     * Type: String
     **/
    uid: 'article',

    /**
     * `type` is used to name the type in GraphQL.
     * If you specify 'post' as a type, then the type of GraphQL will be 'newtPost' and 'allNewtPost'.
     *
     * Optional
     * Type: String
     * Default: uid value
     **/
    type: 'post',

    /**
     * `query` specifies the condition of the content to be fetched.
     * See below for details on available queries.
     * https://github.com/Newt-Inc/newt-client-js#query-fields
     *
     * Optional
     * Type: Object
     **/
    query: {
      or: [
        { title: { match: 'update' } },
        { title: { match: 'アップデート' } }
      ],
      body: { fmt: 'text' },
    },
  }],

  /**
   * `apiType` specifies the API to be used.
   * If you use the CDN API, enter `cdn`; if you use the Newt API, enter `api`.
   *
   * Optional
   * Type: String
   * Default: `cdn`
   **/
  apiType: 'cdn',
}

gatsby-node.js

const path = require('path')

exports.createPages = async ({graphql, actions}) => {
  const {createPage} = actions

  const result = await graphql(`
    {
      allNewtArticle {
        edges {
          node {
            _id
            slug
          }
        }
      }
    }
  `)

  if (result.errors) {
    throw result.errors
  }

  result.data.allNewtArticle.edges.forEach((edge) => {
    createPage({
      path: edge.node.slug,
      component: path.resolve('./src/templates/article.js'),
      context: {
        _id: edge.node._id
      },
    })
  })
}

License

This repository is published under the MIT License.

2.0.18

17 days ago

2.0.17

23 days ago

2.0.16

2 months ago

2.0.15

4 months ago

2.0.13

7 months ago

2.0.14

6 months ago

2.0.11

10 months ago

2.0.12

10 months ago

2.0.10

12 months ago

2.0.9

1 year ago

2.0.7

1 year ago

2.0.6

1 year ago

2.0.8

1 year ago

2.0.5

1 year ago

2.0.3

2 years ago

2.0.4

2 years ago

2.0.2

2 years ago

1.0.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

0.0.2

2 years ago