Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Notion content source implementation #393

Closed
wants to merge 68 commits into from

Conversation

kerwanp
Copy link

@kerwanp kerwanp commented Mar 14, 2023

🚧 This is a work in progress

Supports for Notion

This pull request implements Notion as a content source.

Related issues

Context

Notion is becoming a standard in the industry and almost 100% of our customers use it daily. As a Web Agency we want to provide an easy way for our customers to update the content of their website without relying on us.

We started a while ago the development of NotionCMS a NodeJS library to use Notion as if it was a CMS including a renderer to transform Notion Page Content into HTML.

Unfortunately, there are a lot of problems with the path we decided to took with this tool. This is why we are looking for an alternative and the best solution we found is to implement Notion to Contentlayer.

Documentation

https://www.contentlayer.dev/docs/sources/notion

Rendering content

Notion does not use markdown, it looks like but unfortunately for us it is not.
Instead, it returns objects called blocks of different type (paragraph, heading, etc). More information here.

This is why I created @notion-render/client a library that transform thoses blocks into HTML. The renderer can be extended to override current blocks and add custom ones to handle Notion Plugins.

Roadmap

  • Handle all simple property types
  • Better implementation of Formula (currently the value type is not inferred)
  • Relation property implementation
  • Rollup property implementation
  • Ability to redefine field keys to keep human readable property names on Notion
  • Ability to whitelist properties to generate content without properties containing sensitive values
  • Add required option to properties (pages without thoses properties are not generated)
  • Add ability to filter and sort databases
  • Add pagination iteration system and handle Rate limit
  • Computed fields
  • Create and use a Notion renderer to transform page content (and RichText properties) into HTML
  • Improve performance and codebase architecture
  • Write tests
  • WIP

Example

You can find an example in examples/node-script-notion.

ℹ️ You must have an Internal Integration Token that has access to the databases you want to fetch. You can create one here.

import { makeSource, defineDatabase } from 'contentlayer-source-notion';
import * as notion from '@notionhq/client';

const client = new notion.Client({
    auth: '<my-notion-token>'
})

const Post = defineDatabase(() => ({
    name: 'Post',
    databaseId: '<my-database-id>',
    properties: {
        email: { // Remap properties to a custom key
            label: 'Email', // Properties to remap
            isRequired: true, // Content is not generated if the property is required (defaults to false)
        }
    }
}))

export default makeSource({
    client,
    databaseTypes: [Post]
})

@changeset-bot
Copy link

changeset-bot bot commented Mar 14, 2023

⚠️ No Changeset found

Latest commit: 7591d91

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

💥 An error occurred when fetching the changed packages and changesets in this PR
Some errors occurred when validating the changesets config:
The package or glob expression "examples-*" is specified in the `ignore` option but it is not found in the project. You may have misspelled the package name or provided an invalid glob expression. Note that glob expressions must be defined according to https://www.npmjs.com/package/micromatch.

@kerwanp kerwanp changed the title [WIP] Notion source implementation [WIP] Notion content source implementation Mar 14, 2023
@schickling
Copy link
Collaborator

Very excited to look into this once I'm back from my vacation towards the end of the month. As this is a fairly big change to Contentlayer, it would probably be useful to exchange some DMs via Discord. Feel free to DM me via the Contentlayer Discord channel. :)

@kerwanp
Copy link
Author

kerwanp commented Mar 17, 2023

The contentlayer-source-notion plugin as been released in Alpha-test ! 🎉

You can find the documentation in the description of this PR.

@emilienbidet
Copy link

Keep going @kerwanp ! That's a super work

@stale
Copy link

stale bot commented Jun 8, 2023

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the meta: stale label Jun 8, 2023
@stale stale bot closed this Jun 15, 2023
@schickling schickling reopened this Jun 15, 2023
@stale stale bot removed the meta: stale label Jun 15, 2023
@stale
Copy link

stale bot commented Jul 9, 2023

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the meta: stale label Jul 9, 2023
@airtonix
Copy link

👋🏻 I think I've been trying out the alpha of notion as a content source via contentlayer.

This is my first time using notion.

One blocker for me at the moment is that i cant seem to be able to add any page i want from notion into contentlayer as it looks like i can only source databases?

@stale stale bot removed the meta: stale label Jul 16, 2023
@stale
Copy link

stale bot commented Aug 5, 2023

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the meta: stale label Aug 5, 2023
@stale stale bot closed this Aug 12, 2023
@schickling schickling reopened this Aug 12, 2023
@stale stale bot closed this Aug 21, 2023
@jmuchovej
Copy link

is it possible to add meta: never stale as a label to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants