-
-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #728 from tone-row/dev
v1.57.0
- Loading branch information
Showing
59 changed files
with
333 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,59 @@ | ||
import { VercelRequest, VercelResponse } from "@vercel/node"; | ||
import { dateAsNumber, dateString, niceDate } from "../_lib/_dates"; | ||
import { notion, getNestedProperties } from "../_lib/_notion"; | ||
import { niceDate } from "../_lib/_dates"; | ||
import { notion } from "../_lib/_notion"; | ||
import { z } from "zod"; | ||
import { BlogPost, NotionPost } from "shared"; | ||
|
||
export default async function handler(req: VercelRequest, res: VercelResponse) { | ||
const response = await notion.databases.query({ | ||
database_id: "b7a09b10aa83485b94092269239a8b38", | ||
}); | ||
const posts = response.results.map((page) => { | ||
if (!("properties" in page)) throw new Error("No properties"); | ||
const { properties = {}, id } = page; | ||
const { date, ...props } = getNestedProperties(properties); | ||
if (!("title" in props)) throw new Error("No title"); | ||
if (!("status" in props)) throw new Error("No status"); | ||
if (!("slug" in props)) throw new Error("No slug"); | ||
if (!("description" in props)) throw new Error("No description"); | ||
|
||
if (!date) throw new Error("No date"); | ||
|
||
const sanitizedDate = dateString(date); | ||
const publishDate = niceDate(date); | ||
const rawDate = dateAsNumber(date); | ||
|
||
return { id, rawDate, date: sanitizedDate, publishDate, ...props }; | ||
}); | ||
|
||
const notionPosts = response.results.filter( | ||
isValidNotionPost | ||
) as unknown as NotionPost[]; | ||
|
||
const posts = notionPosts.map(notionPostToBlogPost); | ||
|
||
// Cache for 1 week, stale-while-revalidate | ||
res.setHeader("Cache-Control", "s-maxage=1, stale-while-revalidate"); | ||
|
||
res.json(posts); | ||
} | ||
|
||
const postSchema: z.ZodType<NotionPost> = z.object({ | ||
id: z.string(), | ||
created_time: z.string(), | ||
properties: z.object({ | ||
title: z.object({ | ||
title: z.array(z.object({ plain_text: z.string() })).min(1), | ||
}), | ||
description: z.object({ | ||
rich_text: z.array(z.object({ plain_text: z.string() })).min(1), | ||
}), | ||
status: z.object({ | ||
status: z.object({ name: z.string() }), | ||
}), | ||
slug: z.object({ | ||
rich_text: z.array(z.object({ plain_text: z.string() })).min(1), | ||
}), | ||
}), | ||
}); | ||
|
||
function isValidNotionPost(post: unknown): post is NotionPost { | ||
const parsed = postSchema.safeParse(post); | ||
if (parsed.success) return true; | ||
return false; | ||
} | ||
|
||
function notionPostToBlogPost(post: NotionPost): BlogPost { | ||
return { | ||
id: post.id, | ||
publishDate: new Date(post.created_time).getTime(), | ||
niceDate: niceDate(new Date(post.created_time)), | ||
description: post.properties.description.rich_text[0].plain_text, | ||
slug: post.properties.slug.rich_text[0].plain_text, | ||
status: post.properties.status.status.name, | ||
title: post.properties.title.title[0].plain_text, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+3.94 KB
(120%)
app/public/template-screenshots/thumb_network-diagram-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+0 Bytes
(100%)
app/public/template-screenshots/thumb_network-diagram-dark.ts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+0 Bytes
(100%)
app/public/template-screenshots/thumb_network-diagram-icons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.