DEV Community

Cover image for Use Notion as a database for your Next.JS Blog

Use Notion as a database for your Next.JS Blog

Martin PAUCOT on May 13, 2023

Notion is an extremely powerful tool to manage your content by creating a database you can even add properties to pages: publication date, tags, et...
Collapse
 
huytq085 profile image
Huy Tran

@notion-render/hljs-plugin A plugin to fetch website metadata to render bookmarks
need to be modified to:
@notion-render/bookmark-plugin

Collapse
 
hasanulhaquebanna profile image
Hasanul Haque Banna

The question how can I decode from html/render? Because for doing SEO it is mandatory to implement where to put necessary content so how can I get according to SEO needs?

Collapse
 
martinp profile image
Martin PAUCOT

Hey! I do not entirely understand your needs. But when fetching the page fetchPageBySlug(params.slug) it returns the page properties aswell.

You can use it inside generateMetadata to use the page here is how I do it on my blog (with dev.to articles).

You can aswell use generateStaticParams to statically generate all your blog pages at build time.

The result: martin-paucot.fr

Collapse
 
hasanulhaquebanna profile image
Hasanul Haque Banna

for metadata instances there has, image property as well how can I get that using notion?

Thread Thread
 
martinp profile image
Martin PAUCOT

When fetching a page, you would have the properties as well.
developers.notion.com/reference/re...

Collapse
 
hasanulhaquebanna profile image
Hasanul Haque Banna • Edited

plugin issue
I am getting this error;

Thread Thread
 
martinp profile image
Martin PAUCOT

If I remember well the plugin expect a configuration, even empty. So hljsPlugin({})

Collapse
 
alvarolorentedev profile image
Alvaro

I have also used it as an MVP for an API, i would recommend to put things behind a lambda or service to have a contract layer and not be tide to the query or response model from Notion.

Collapse
 
martinp profile image
Martin PAUCOT • Edited

The model sent to the Notion API is really complex for no reason (in my opinion).

This is why I am working on NotionX! A library that makes working with Notion extremely easy.

Feel free to follow the project and my Twitter to know when it gets published!

Collapse
 
coffeegerm profile image
David Yarzebinski

Would love to help with this if there's a possibility of collaboration!

Collapse
 
itsjavidotcom profile image
Javi Aguilar

I looked at the code of NotionX and looks much cleaner than the official SDK. Do you have plans to release it on npm to start trying it? :)

Collapse
 
ch3ber profile image
Eber Alejo

Looks so interesting, great job!

Collapse
 
rmmgc profile image
Ramo Mujagic

Really nice idea.
Tnx for sharing.

Collapse
 
maxbrych profile image
MaxBrych

cool stuff

Collapse
 
jrrs1982 profile image
Jeremy Smith

Keen to try this tomorrow!!

Collapse
 
madzimai profile image
Netsai

This is really awesome!

Collapse
 
karaca19 profile image
Bora Karaca

Interesting... Will try this out tomorrow or later

Collapse
 
jonmccon profile image
jonmccon

This is really awesome! I've pulled content with the notion api but it's quite tedious. Does your work support metadata or database views? Great work, thank you!

Collapse
 
martinp profile image
Martin PAUCOT

Hey! Thanks for the feedback! I am actually working on an improved fully typed Notion Client, currently it only supports fetching but in a near future the idea is to be able to use it like a library github.com/kerwanp/notionx.

If you talk about external website metadata like the Bookmark block, the Bookmark plugin will fetch them from the targeted website to render the block.

I never had to query database views before but it will be definitely implemented in the future library I'm working on.

Collapse
 
tilakkhatri profile image
Tilak Khatri

I am using app route of nextjs13 approute , this below api call showing me cors error how to solve it.

Image description

Image description

And calling it here.

Image description

Hoping for solving idea :)

Collapse
 
iamhectorsosa profile image
Hector Sosa • Edited

This is a pretty cool concept! I experimented with it in the past too! Framing some of these screenshots would've been chef's kiss! @martinp I've built a simple OSS tool for creating engaging screenshots with ease. Check it out and let me know what you think! Cheers!

github.com/ekqt/screenshot

Collapse
 
thesonpb profile image
Nguyễn Thế Sơn • Edited

Hi Martin,

I used it in my React application, although i have block, the htmlTemp is still an empty string ("")

Image description

Here is my code:

                const block = await getBlogBlock(id);
                const renderer = new NotionRenderer({
                    client: notion,
                });
                renderer.use(hljsPlugin());
                renderer.use(bookmarkPlugin());

                const htmlTemp = await renderer.render(block);
                setHtml(htmlTemp);
Enter fullscreen mode Exit fullscreen mode

The block looks like this when i debug:

Image description

Could you please provide some guidance on how to fix this or point me in the right direction? Any help would be greatly appreciated.

Thank you in advance!

Collapse
 
martinp profile image
Martin PAUCOT

Hi! The render functions uses rest parameters. Replacing renderer.render(block) by renderer.render(...block) should resolve your issue! (and you can plurialize block at the same occasion).

Basically, a page content contains a list of blocks (paragraphs, bookmarks, quotes, etc). This is why your getBlogBlock function returns an array

Collapse
 
awaisalwaisy profile image
Alwaisy al-waisy

what is their geneorus limiT. Airtable can also do the same.

Collapse
 
martinp profile image
Martin PAUCOT

Airtable is cool but Notion is mostly use by marketing and sales team.
It makes way easier for anyone to write content.

And in my case, sometimes when I have an idea I simply open the Notion App and start writing content and set the status of my page to "Draft".

And when it is ready to be published, I just drag the page within my Kanban view to "Published" and tada it appears on the website!

Collapse
 
awaisalwaisy profile image
Alwaisy al-waisy

so simple. How about the limits. 1000 blcoks in free notion.

Thread Thread
 
martinp profile image
Martin PAUCOT

I have no problems of paying the tools I use daily, but if in your case using Airtable makes more sense, go for it!

If you are intersted, I also wrote an article on how to directly fetch your DEV.to posts for your blog Build a Blog using Next.JS and DEV.to

Collapse
 
kasperbuchholtz profile image
Kb

Hello, i have a question about showing the notion pages as a webpage in your blogpost it mentions the path blog/[slug] so the url would be /blog/my-first-post...

i can get the page to show but not any of the content...

Collapse
 
lluciferr profile image
snow bell

How to resolve cors policy

Image description

Collapse
 
martinp profile image
Martin PAUCOT

Hi ! As shown in the error your database ID is not defined. With a correct one it should work well

Collapse
 
airtonix profile image
Zenobius Jiricek

Use content layer instead

Collapse
 
martinp profile image
Martin PAUCOT

Hey Zenobius! I am the author of the Notion Contentlayer implementation 😉
github.com/kerwanp/contentlayer-so...

Contentlayer is great when working on a Static Website but it means re-building if you want latest up to date data.

This is why I am working on NotionX, a Notion Client with super powers that is usable like an ORM.

Collapse
 
akilesh profile image
Akilesh

I am working on Notion to Blog lamento for those doesn't want to code