${card.properties.Name.title[0].plain_text}
10 |${card.properties.Content.rich_text[0].plain_text} 12 |
13 |├── .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 | ${card.properties.Content.rich_text[0].plain_text}
12 |
9 |
${card.properties.Name.title[0].plain_text}
10 |