Skip to content

Commit 498a61a

Browse files
committed
feat: update bookmarks page cache
remove useless dependencies
1 parent 825f257 commit 498a61a

File tree

3 files changed

+245
-235
lines changed

3 files changed

+245
-235
lines changed

package.json

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414
"dependencies": {
1515
"@notionhq/client": "^2.2.0",
1616
"@plaiceholder/next": "^2.5.0",
17-
"fast-glob": "^3.2.11",
18-
"framer-motion": "^7.2.1",
17+
"fast-glob": "^3.2.12",
18+
"framer-motion": "^7.4.0",
1919
"gray-matter": "^4.0.3",
2020
"javascript-time-ago": "^2.5.7",
21-
"lodash": "^4.17.21",
22-
"next": "^12.2.5",
21+
"next": "^12.3.1",
2322
"next-mdx-remote": "^4.1.0",
2423
"notion-client": "^6.13.8",
2524
"notion-utils": "^6.13.4",
@@ -30,28 +29,27 @@
3029
"react": "^18.2.0",
3130
"react-dom": "^18.2.0",
3231
"react-icons": "^4.4.0",
33-
"react-notion-x": "^6.13.9",
32+
"react-notion-x": "^6.13.10",
3433
"reactdom": "^2.0.0",
3534
"sharp": "^0.31.0",
3635
"styled-components": "^5.3.5",
3736
"styled-system": "^5.1.5"
3837
},
3938
"devDependencies": {
4039
"@types/javascript-time-ago": "^2.0.3",
41-
"@types/lodash": "^4.14.184",
42-
"@types/react": "^18.0.18",
40+
"@types/react": "^18.0.21",
4341
"@types/styled-components": "^5.1.26",
4442
"@types/styled-system": "^5.1.15",
45-
"@typescript-eslint/parser": "^5.36.2",
46-
"eslint": "^8.23.0",
47-
"eslint-config-next": "^12.2.5",
43+
"@typescript-eslint/parser": "^5.38.1",
44+
"eslint": "^8.24.0",
45+
"eslint-config-next": "^12.3.1",
4846
"eslint-config-prettier": "^8.5.0",
4947
"eslint-plugin-import": "^2.26.0",
5048
"eslint-plugin-prettier": "^4.2.1",
5149
"husky": "8.0.1",
5250
"lint-staged": "^13.0.3",
53-
"next-sitemap": "^3.1.21",
51+
"next-sitemap": "^3.1.23",
5452
"pretty-quick": "^3.1.3",
55-
"typescript": "^4.8.2"
53+
"typescript": "^4.8.3"
5654
}
5755
}

pages/bookmarks.tsx

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import React from 'react';
22
import Head from 'next/head';
3-
import { GetStaticPropsResult } from 'next';
3+
import { GetServerSidePropsContext, InferGetServerSidePropsType } from 'next';
44
import Image from 'next/image';
55
import TimeAgo from 'javascript-time-ago';
6-
import { compact } from 'lodash';
76
import { Title, Container, Text, Grid, Link, Card } from '@components';
87

98
import en from 'javascript-time-ago/locale/en.json';
@@ -13,18 +12,9 @@ import { getBookmarks } from '../notion';
1312
TimeAgo.addDefaultLocale(en);
1413
const timeAgo = new TimeAgo('en-US');
1514

16-
export interface Bookmark {
17-
id: string;
18-
created: string;
19-
name: string;
20-
url: string;
21-
}
22-
23-
interface BookmarksProps {
24-
bookmarks: ReadonlyArray<Bookmark>;
25-
}
26-
27-
const Bookmarks = ({ bookmarks }: BookmarksProps): JSX.Element => (
15+
const Bookmarks = ({
16+
bookmarks,
17+
}: InferGetServerSidePropsType<typeof getServerSideProps>): JSX.Element => (
2818
<Container marginBottom="5rem">
2919
<Head>
3020
<title>Bookmarks</title>
@@ -90,34 +80,50 @@ const Bookmarks = ({ bookmarks }: BookmarksProps): JSX.Element => (
9080
</Container>
9181
);
9282

83+
export interface Bookmark {
84+
id: string;
85+
created: string;
86+
name: string;
87+
url: string;
88+
}
89+
9390
const formatBookmarks = ({
9491
results,
9592
}: QueryDatabaseResponse): ReadonlyArray<Bookmark> =>
96-
compact(
97-
results.map((result) => {
98-
if (
99-
result.object === 'page' &&
100-
'url' in result &&
101-
result.properties?.Created?.type === 'created_time' &&
102-
result.properties?.URL?.type == 'url' &&
103-
result.properties.URL.url &&
104-
result.properties?.Name?.type == 'title' &&
105-
result.properties.Name.title?.[0]?.type === 'text'
106-
) {
107-
return {
93+
results.reduce<Array<Bookmark>>((acc, result) => {
94+
if (
95+
result.object === 'page' &&
96+
'url' in result &&
97+
result.properties?.Created?.type === 'created_time' &&
98+
result.properties?.URL?.type == 'url' &&
99+
result.properties.URL.url &&
100+
result.properties?.Name?.type == 'title' &&
101+
result.properties.Name.title?.[0]?.type === 'text'
102+
) {
103+
return [
104+
...acc,
105+
{
108106
id: result.id,
109107
url: result.properties.URL.url,
110108
created: result.properties.Created.created_time,
111109
name: result.properties.Name.title[0].plain_text,
112-
};
113-
}
114-
}),
115-
);
110+
},
111+
];
112+
}
113+
114+
return acc;
115+
}, []);
116116

117-
export const getServerSideProps = async (): Promise<
118-
GetStaticPropsResult<BookmarksProps>
119-
> => {
117+
export const getServerSideProps = async ({
118+
res,
119+
}: GetServerSidePropsContext) => {
120120
const bookmarks = await getBookmarks();
121+
122+
res.setHeader(
123+
'Cache-Control',
124+
'public, s-maxage=3600, stale-while-revalidate=60',
125+
);
126+
121127
return {
122128
props: {
123129
bookmarks: formatBookmarks(bookmarks),

0 commit comments

Comments
 (0)