Skip to content

Commit

Permalink
Merge pull request #21 from gabe-frasz/add-notion-cms
Browse files Browse the repository at this point in the history
feat: add notion as cms
  • Loading branch information
diego3g authored Feb 27, 2023
2 parents b5d61b4 + 655e55d commit 228e58b
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 67 deletions.
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Connection to Notion API
# see: https://developers.notion.com/docs/create-a-notion-integration
NOTION_API_KEY=""

# Edge Config is a key-value data store associated with your Vercel account
# see: https://vercel.com/docs/concepts/edge-network/edge-config/get-started
EDGE_CONFIG="https://edge-config.vercel.com/your_edge_config_id_here?token=your_edge_config_read_access_token_here"
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
},
"dependencies": {
"@next/font": "13.1.6",
"@notionhq/client": "^2.2.3",
"@radix-ui/react-collapsible": "^1.0.1",
"@radix-ui/react-dropdown-menu": "^2.0.2",
"@radix-ui/react-scroll-area": "^1.0.2",
"@types/node": "18.13.0",
"@types/react": "18.0.27",
"@types/react-dom": "18.0.10",
"@vercel/edge-config": "^0.1.1",
"eslint": "8.33.0",
"eslint-config-next": "13.1.6",
"lucide-react": "^0.112.0",
Expand Down
90 changes: 90 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 7 additions & 11 deletions src/app/others/dev-setup/page.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
import { CodePreview } from '@/components/CodePreview'
import { getCodeBlockFromNotion } from '@/lib/notion-client'
import { getNotionPagesId } from '@/lib/vercel-edge-config'
import shiki from 'shiki'

export const metadata = {
title: 'Dev Setup',
}

const markdown = `
# Dev Setup
- MacBook M1 Max (64gb Memory)
- LG 25" UltraWide Display
That's it, nothing more.
`.trim()

export default async function DevSetup() {
const { setup_dev } = await getNotionPagesId()
const { content } = await getCodeBlockFromNotion(setup_dev)

const highlighter = await shiki.getHighlighter({
theme: 'rose-pine-moon',
})

const code = highlighter.codeToHtml(markdown, { lang: 'md' })
const code = highlighter.codeToHtml(content, { lang: 'md' })

return <CodePreview code={code} />
}
}
27 changes: 6 additions & 21 deletions src/app/others/gaming-setup/page.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,21 @@
import { CodePreview } from '@/components/CodePreview'
import { getCodeBlockFromNotion } from '@/lib/notion-client'
import { getNotionPagesId } from '@/lib/vercel-edge-config'
import shiki from 'shiki'

export const metadata = {
title: 'Gaming Setup',
}

const markdown = `
# Gaming Setup
- Intel Core i5-9600KF 3.7Ghz
- 2x HyperX Fury 16GB 3000Mhz
- Gigabyte Z390M Gaming
- Cooler Master ATX 500W 80 Plus
- 2x Corsair SSD MP510 480GB NVMe
- Gigabyte NVIDIA GeForce RTX 2060 6G
## Peripherals
- Logitech G PRO Wireless Mouse
- Keychron K2 Keyboard (Brown Switch)
- Samsung 23.5" Curved 144hz 1ms Display
That's it, nothing more.
`.trim()

export default async function GamingSetup() {
const { setup_gaming } = await getNotionPagesId()
const { content } = await getCodeBlockFromNotion(setup_gaming)

const highlighter = await shiki.getHighlighter({
theme: 'rose-pine-moon',
})

const code = highlighter.codeToHtml(markdown, { lang: 'md' })
const code = highlighter.codeToHtml(content, { lang: 'md' })

return <CodePreview code={code} />
}
20 changes: 7 additions & 13 deletions src/app/terminal/fish/page.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
import { CodePreview } from '@/components/CodePreview'
import { getCodeBlockFromNotion } from '@/lib/notion-client'
import { getNotionPagesId } from '@/lib/vercel-edge-config'
import shiki from 'shiki'

export const metadata = {
title: 'Fish',
}

const fishConfig = `if status is-interactive
# Commands to run in interactive sessions can go here
end
set SPACEFISH_PROMPT_ADD_NEWLINE false
starship init fish | source
# Aliases
# alias cat="bat --theme=\$(defaults read -globalDomain AppleInterfaceStyle &> /dev/null && echo default || echo GitHub)"`

export default async function FishConfig() {
const { terminal_fish } = await getNotionPagesId()
const { content } = await getCodeBlockFromNotion(terminal_fish)

const highlighter = await shiki.getHighlighter({
theme: 'rose-pine-moon',
})

const code = highlighter.codeToHtml(fishConfig, { lang: 'fish' })
const code = highlighter.codeToHtml(content, { lang: 'fish' })

return <CodePreview code={code} raw={fishConfig} />
return <CodePreview code={code} raw={content} />
}
28 changes: 6 additions & 22 deletions src/app/terminal/general/page.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,21 @@
import { CodePreview } from '@/components/CodePreview'
import { getCodeBlockFromNotion } from '@/lib/notion-client'
import { getNotionPagesId } from '@/lib/vercel-edge-config'
import shiki from 'shiki'

export const metadata = {
title: 'Terminal',
}

const markdown = `
# General
Currently I'm using the combo Fish + Starship in my terminal.
Fish Shell: https://fishshell.com/
Starship: https://starship.rs/
---
I'm also using Warp as my terminal emulator.
Warp: https://www.warp.dev/
---
For the theme, I chose Rosé Pine Moon variant:
Theme: https://github.com/austintraver/warp-theme/blob/main/base16_rose_pine_moon.yaml
`.trim()

export default async function General() {
const { terminal_general } = await getNotionPagesId()
const { content } = await getCodeBlockFromNotion(terminal_general)

const highlighter = await shiki.getHighlighter({
theme: 'rose-pine-moon',
})

const code = highlighter.codeToHtml(markdown, { lang: 'md' })
const code = highlighter.codeToHtml(content, { lang: 'md' })

return <CodePreview code={code} />
}
20 changes: 20 additions & 0 deletions src/lib/notion-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Client, isFullBlock } from '@notionhq/client'
import { CodeBlockObjectResponse } from '@notionhq/client/build/src/api-endpoints'

export const notionClient = new Client({ auth: process.env.NOTION_API_KEY })

export async function getCodeBlockFromNotion(pageId: string) {
const { results } = await notionClient.blocks.children.list({ block_id: pageId })

const codeBlock = results.find(
block => isFullBlock(block) && block.type === 'code'
) as CodeBlockObjectResponse | undefined

if (!codeBlock) {
throw new Error(`Failed to fetch Notion content of ID: ${pageId}`)
}

const { plain_text } = codeBlock.code.rich_text[0]

return { content: plain_text }
}
Loading

1 comment on commit 228e58b

@vercel
Copy link

@vercel vercel bot commented on 228e58b Feb 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.