Skip to content

Commit 1ef8e99

Browse files
authored
Merge pull request #31 from 01-binary/update-lib
Update lib
2 parents e02b8bd + df711c8 commit 1ef8e99

24 files changed

+373
-5488
lines changed

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@
1616
"jotai": "^2.8.0",
1717
"lodash": "^4.17.21",
1818
"next": "^13.4.4",
19-
"notion-to-utils": "^0.4.21",
19+
"notion-to-jsx": "^1.2.7",
20+
"notion-to-utils": "^1.0.2",
2021
"p-map": "^7.0.2",
22+
"prismjs": "^1.30.0",
2123
"react": "^18.2.0",
2224
"react-dom": "^18.2.0",
2325
"react-icons": "^4.9.0",
24-
"react-notion-x": "^6.16.0",
2526
"rss": "^1.2.2"
2627
},
2728
"devDependencies": {
2829
"@types/lodash": "^4.14.195",
2930
"@types/node": "18.11.10",
31+
"@types/prismjs": "^1.26.5",
3032
"@types/react": "18.0.26",
3133
"@types/react-dom": "18.0.9",
3234
"@types/rss": "^0.0.32",
@@ -51,5 +53,6 @@
5153
"prettier --write",
5254
"eslint --fix"
5355
]
54-
}
56+
},
57+
"packageManager": "[email protected]+sha512.ff4579ab459bb25aa7c0ff75b62acebe576f6084b36aa842971cf250a5d8c6cd3bc9420b22ce63c7f93a0857bc6ef29291db39c3e7a23aab5adfd5a4dd6c5d71"
5558
}

pages/_app.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import type { AppProps } from 'next/app';
22

33
import Layout from '@/components/layout';
44

5-
import 'prismjs/themes/prism-tomorrow.css';
6-
import 'katex/dist/katex.min.css';
5+
import 'notion-to-jsx/dist/index.css';
76
import '@/assets/styles/index.css';
8-
import '@/assets/styles/notion-x.css';
7+
8+
import 'prismjs/themes/prism-tomorrow.css';
99

1010
const App = ({ Component, pageProps }: AppProps) => {
1111
return (

pages/about.tsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
import { GetStaticProps } from 'next';
2-
import { NotionRenderer } from 'react-notion-x';
2+
import { NotionBlock, Renderer } from 'notion-to-jsx';
33

4-
import { ExtendedRecordMap as EmbeddedRecordMap } from '@/interfaces/notion';
5-
import { getPage } from '@/utils';
4+
import { notionClient } from '@/utils';
65

76
import PageHead from '@/components/common/PageHead';
87

98
import { REVALIDATE_TIME } from '@/assets/constants';
109

1110
interface Props {
12-
recordMap: EmbeddedRecordMap;
11+
blocks: NotionBlock[];
1312
}
1413

15-
const AboutPage = ({ recordMap }: Props) => {
14+
const AboutPage = ({ blocks }: Props) => {
1615
return (
1716
<>
1817
<PageHead title="About" />
19-
<article>
20-
<NotionRenderer
21-
recordMap={recordMap as Parameters<typeof NotionRenderer>[0]['recordMap']}
22-
/>
23-
</article>
18+
<Renderer blocks={blocks} />
2419
</>
2520
);
2621
};
@@ -32,11 +27,10 @@ export const getStaticProps: GetStaticProps<Props> = async () => {
3227

3328
if (!aboutId) throw new Error('NOTION_ABOUT_ID is not defined');
3429

35-
const recordMap = await getPage(aboutId);
36-
30+
const blocks = (await notionClient.getPageBlocks(aboutId)) as NotionBlock[];
3731
return {
3832
props: {
39-
recordMap,
33+
blocks,
4034
},
4135
revalidate: REVALIDATE_TIME,
4236
};

pages/api/cover-image.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import type { NextApiRequest, NextApiResponse } from 'next';
22

3-
import { getPage, getPageCoverImage } from '@/utils';
3+
import { notionClient } from '@/utils';
44

55
import { IMAGE_MAX_AGE } from '@/assets/constants';
66

77
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
88
const { pageId } = req.query;
99

1010
try {
11-
const recordMap = await getPage(pageId as string);
12-
const notionCoverUrl = getPageCoverImage(recordMap) as unknown as URL;
11+
const properties = await notionClient.getPageProperties(pageId as string);
12+
const notionCoverUrl = properties?.coverUrl || '';
1313
const response = await fetch(notionCoverUrl);
1414
const contentType = response.headers.get('content-type');
1515

pages/api/profile-image.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,10 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
88
if (!process.env.NOTION_PROFILE_ID) throw new Error('NOTION_PROFILE_ID is not defined');
99
const pageId = process.env.NOTION_PROFILE_ID;
1010
try {
11-
const response = await notionClient.pages.retrieve({
12-
page_id: pageId,
13-
});
11+
const url = await notionClient.getFileUrl(pageId, 'media');
1412

15-
// 타입 체크를 위한 조건문 추가
16-
if (!('properties' in response) || !response.properties.media) {
17-
return res.status(404).json({ message: 'Media files not found' });
18-
}
19-
20-
// 타입 선언 후 안전하게 접근
21-
const mediaProperty = response.properties.media;
22-
23-
// media 파일 배열이 비어있지 않은지 확인 후 파일 URL 추출
24-
if (
25-
'files' in mediaProperty &&
26-
mediaProperty.files.length > 0 &&
27-
'file' in mediaProperty.files[0]
28-
) {
29-
const fileUrl = mediaProperty.files[0].file.url;
30-
const response = await fetch(fileUrl);
13+
if (url) {
14+
const response = await fetch(url);
3115
const contentType = response.headers.get('content-type');
3216

3317
if (!contentType) throw new Error('content header does not exist');

pages/posts/[slug].tsx

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,40 @@
11
import { ParsedUrlQuery } from 'querystring';
22

33
import { GetStaticPaths, GetStaticProps } from 'next';
4-
import { NotionRenderer } from 'react-notion-x';
4+
import { NotionBlock, Renderer } from 'notion-to-jsx';
55

6-
import PostRenderer from '@/features/posts/Renderer';
7-
import { ExtendedRecordMap } from '@/interfaces/notion';
8-
import { getIdBySlug, getNotionPosts, getPage, getPageProperties, getSlugs } from '@/utils';
9-
import { getPreviewImageFromRecordMap } from '@/utils';
10-
import { siteConfig } from 'site.config';
6+
import { getIdBySlug, getNotionPosts, getSlugs, notionClient } from '@/utils';
117

128
import Giscus from '@/components/common/Giscus';
139
import PageHead from '@/components/common/PageHead';
1410

1511
import { REVALIDATE_TIME } from '@/assets/constants';
1612

17-
import { getPageTitle } from '@/utils/getPageTitle';
18-
1913
interface Props {
20-
recordMap: ExtendedRecordMap;
14+
blocks: NotionBlock[];
2115
seo: {
2216
title: string;
2317
description: string;
2418
keywords: string;
25-
ogImage: string | null;
19+
coverUrl: string;
2620
};
2721
}
2822

29-
const PostPage = ({ recordMap, seo: { title, description, keywords, ogImage } }: Props) => {
30-
if (!recordMap) return null;
23+
const PostPage = ({ blocks, seo: { title, description, keywords, coverUrl } }: Props) => {
24+
if (!blocks) return null;
3125
return (
3226
<>
3327
<PageHead
3428
title={title}
3529
description={description}
3630
keywords={keywords}
37-
image={ogImage}
31+
image={coverUrl}
32+
/>
33+
<Renderer
34+
title={title}
35+
cover={coverUrl}
36+
blocks={blocks}
3837
/>
39-
<article>
40-
<PostRenderer recordMap={recordMap as Parameters<typeof NotionRenderer>[0]['recordMap']} />
41-
</article>
4238
<div className="mx-auto max-w-[900px] px-4">
4339
<Giscus />
4440
</div>
@@ -55,24 +51,17 @@ interface PostParams extends ParsedUrlQuery {
5551
export const getStaticProps: GetStaticProps<Props, PostParams> = async ({ params }) => {
5652
const { slug } = params as PostParams;
5753
const id = await getIdBySlug(slug as string, process.env.NOTION_POST_DATABASE_ID as string);
58-
const recordMap = await getPage(id);
59-
const { description, keywords } = await getPageProperties(id);
60-
const previewImages = await getPreviewImageFromRecordMap(recordMap);
61-
62-
const title = getPageTitle(recordMap) as string;
63-
const ogImage = `${siteConfig.url}/api/cover-image?pageId=${id}`;
54+
const blocks = (await notionClient.getPageBlocks(id)) as NotionBlock[];
55+
const properties = await notionClient.getPageProperties(id);
6456

6557
return {
6658
props: {
67-
recordMap: {
68-
...recordMap,
69-
preview_images: previewImages,
70-
} as ExtendedRecordMap,
59+
blocks,
7160
seo: {
72-
title,
73-
description,
74-
keywords,
75-
ogImage,
61+
title: properties?.['Name'] || '',
62+
description: properties?.['Desc'] || '',
63+
keywords: properties?.['Category']?.['name'] || '',
64+
coverUrl: properties?.['coverUrl'] || '',
7665
},
7766
},
7867
revalidate: REVALIDATE_TIME,

pages/sitemap.xml.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ export const getServerSideProps: GetServerSideProps = async ({ res }) => {
1010
if (!process.env.NOTION_POST_DATABASE_ID)
1111
throw new Error('NOTION_POST_DATABASE_ID is not defined');
1212
const databaseItems = await getNotionPosts(process.env.NOTION_POST_DATABASE_ID);
13-
1413
res.setHeader('Content-Type', 'text/xml');
1514
res.write(generateSitemap(databaseItems));
1615
res.end();

src/assets/styles/index.css

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,15 @@
66

77
body {
88
font-family: Spoqa Han Sans Neo, 'Noto Sans KR', -apple-system, BlinkMacSystemFont, system-ui,
9-
Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Open Sans, Helvetica Neue, sans-serif;
9+
Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Open Sans, Helvetica Neue, sans-serif !important;
1010

1111
min-width: 360px;
1212
}
1313

14-
.notion-page {
15-
padding-bottom: calc(max(5vh, 32px)) !important;
16-
line-height: 1.65;
17-
}
18-
19-
.notion-text {
20-
padding: 0.5em 2px;
21-
}
22-
23-
.notion-page-cover-wrapper,
24-
.notion-page-cover-wrapper span,
25-
.notion-page-cover-wrapper img {
26-
max-width: 1200px !important;
27-
border-radius: 24px;
28-
}
29-
30-
.notion-collection-page-properties {
31-
display: none !important;
32-
}
33-
34-
@media only screen and (max-width: 1200px) {
35-
.notion-page-cover-wrapper,
36-
.notion-page-cover-wrapper span,
37-
.notion-page-cover-wrapper img {
38-
border-radius: 0;
14+
/* Prism.js 스타일 오버라이드 */
15+
@layer utilities {
16+
code[class*='language-'],
17+
pre[class*='language-'] {
18+
font-size: 0.9em !important;
3919
}
4020
}
41-
42-
@media (min-width: 1300px) and (min-height: 300px) {
43-
.notion-page-content-has-aside {
44-
width: calc((97vw + var(--notion-max-width)) / 2);
45-
}
46-
}
47-
48-
.notion-page-cover-wrapper {
49-
box-shadow: 2px 2px 8px 4px rgba(15, 15, 15, 0.1);
50-
}
51-
52-
.notion-aside-table-of-contents-header {
53-
display: none;
54-
}

0 commit comments

Comments
 (0)