A Gatsby source plugin for importing articles made in Notion into your Gatsby application using Notion API.
# using npm
npm install gatsby-source-notion-article
# using yarn
yarn add gatsby-source-notion-article
Create a new integration. It will give you access to a token that will be used in Gatsby Source Notion Article. Once it's created, copy your token and keep it for the next step.
Duplicate this article database template to ensure your articles follows the same format as this plugin. Don't forget to share this new database with the integration you just created.
Create an .env file at the root of your Gatsby project. You can copy-paste the .env.example
from this Github repository.
https://www.notion.so/myworkspace/a8aec43384f447ed84390e8e42c2e089?v=...
|--------- Database ID --------|
NOTION_KEY=<your-notion-token>
NOTION_DATABASE_ID=<your-notion-database-id>
// In your gatsby-config.js
module.exports = {
plugins: [
{
resolve: `gatsby-source-notion-article`,
options: {
// Learn about environment variables: https://gatsby.dev/env-vars
token: process.env.NOTION_KEY, // required
databaseId: process.env.NOTION_DATABASE_ID, // required
params: {
page_size: 3, // optional, default is 100
filter: {} // optional
sort: {
} // optional
}
}
},
],
}
Name | Type | Default | Description |
---|---|---|---|
token |
string | [required] The token from Notion could be find on your integration |
|
databaseId |
string | [required] The databaseId is the alphanumerical value following the name of your workspace in the sharing URL. |
|
params |
object | The params object |
|
params.page_size |
number | 100 | How many articles you want Notion to query |
params.filter |
object | An object with filters passed to Notion | |
params.sort |
object | An option with sort options passed to Notion | |
debug |
boolean | false | Enable the debug mode for Notion |
unsupported |
boolean | false | Shows in the body a message if the block is not supported. This can be enable only in development mode. |
The Notion API being in beta, only some block elements are currently supported:
- Headings (1, 2, 3)
- Paragraphs
- Bullet and numbered list
- To do
- Toggle
- Child page
{
allNotionArticles {
edges {
node {
id
title
body
createdAt
updatedAt
}
}
}
}
{
notionArticles {
id
title
body
createdAt
updatedAt
}
}
Check our example project of the Gatsby plugin implementation.
// Quick example
const Component = {
const data = useStaticQuery(graphql`
query Notion {
notionArticles {
body
}
}
`);
return (
<div dangerouslySetInnerHTML={{ __html: data.notionArticles.body }} />
);
};
If you've ever wanted to contribute to open source, and a great cause, now is your chance!
See the contributing docs for more information.
Feel free to open a discussion if you have any question or suggestion in regards to this plugin.
Thanks goes to these wonderful people
David Dias 💻 📖 🚇 |
(emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!