├── .gitignore ├── netlify.toml ├── package.json ├── functions └── fetchNotion.js ├── main.js ├── README.md ├── favicon.svg └── index.html /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | dist 4 | dist-ssr 5 | *.local 6 | # Local Netlify folder 7 | .netlify 8 | -------------------------------------------------------------------------------- /netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | functions = "functions" 3 | [[redirects]] 4 | from = "/api/*" 5 | to = "/.netlify/functions/:splat" 6 | status = 200 -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "notion-cms", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "dev": "vite", 6 | "build": "vite build", 7 | "preview": "vite preview" 8 | }, 9 | "devDependencies": { 10 | "netlify-cli": "^8.0.20", 11 | "vite": "^2.7.0" 12 | }, 13 | "dependencies": { 14 | "@notionhq/client": "^0.4.9" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /functions/fetchNotion.js: -------------------------------------------------------------------------------- 1 | const { Client } = require('@notionhq/client'); 2 | 3 | const { NOTION_KEY, NOTION_DB } = process.env; 4 | 5 | // Initializing a client 6 | const notion = new Client({ 7 | auth: NOTION_KEY, 8 | }); 9 | 10 | exports.handler = async function (event, context) { 11 | try { 12 | const response = await notion.databases.query({ 13 | database_id: NOTION_DB, 14 | filter: { 15 | property: 'Status', 16 | select: { 17 | equals: 'Live', 18 | }, 19 | }, 20 | }); 21 | return { 22 | statusCode: 200, 23 | body: JSON.stringify(response), 24 | }; 25 | } catch (e) { 26 | console.error(e); 27 | return { 28 | statusCode: 500, 29 | body: e.toString(), 30 | }; 31 | } 32 | }; 33 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | async function fetchDataFromAPIEndpoint() { 2 | const cards = await fetch('/api/fetchNotion').then((res) => res.json().then((data) => data.results)); 3 | document.querySelector('.card-container').innerHTML = cards 4 | .map( 5 | (card) => ` 6 |
7 | ${card.properties.Name.title[0].plain_text} 9 |

${card.properties.Name.title[0].plain_text}

10 |
11 |

${card.properties.Content.rich_text[0].plain_text} 12 |

13 |
14 | ${card.properties.Btn_text.rich_text[0].plain_text} 15 |
16 | ` 17 | ) 18 | .join(''); 19 | } 20 | fetchDataFromAPIEndpoint(); 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # How to Use Notion as a CMS 2 | 3 | Notion is a powerful online database tool with nearly infinite flexibility. For this reason, it’s attracted dedicated users since it was first launch. In 2021, it published a public Notion API in beta, making it yet more accessible and customizable! In this video series, I'll show you how to use Notion as a light-weight CMS. While not ideal for scaffolding out an entire site, it can act as a very capable CMS for users with mostly static content. For the one or two sections on your site that need regular updating, why not use something like Notion? 4 | 5 | I'll show you how to: 6 | 1. Create the basic site with ViteJS and Open Props using HTML and CSS 7 | 2. Set up Notion and create and add an API Integration 8 | 3. Publish your site to Netlify for free 9 | 4. Create a Netlify serverless function with the Notion SDK for JavaScript and the Netlify CLI (including environmental variables) 10 | 5. How to fetch the live Notion data from your Netlify serverless function 11 | 6. Write a skeleton loading animation to improve the site UX 12 | 13 | 🔗 Key Links for the Series 🔗 14 | - GitHub: https://github.com/coding-in-public/notion-cms 15 | - Live Code: https://codinginpublic.dev/projects/notion-cms/ 16 | 17 | --------------------------------------- 18 | 19 | 🌐 Connect With Me 🌐 20 | - Website: https://www.codinginpublic.dev 21 | - Blog: https://www.chrispennington.blog 22 | - Twitter: https://twitter.com/cpenned 23 | -------------------------------------------------------------------------------- /favicon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Notion CMS 6 | 7 | 8 | 9 | 10 | 11 | 78 | 79 | 80 | 81 |
82 |
83 | 132 | 133 | 134 | 135 | --------------------------------------------------------------------------------