forked from ijjk/notion-blog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Next 9.3 with preview mode (ijjk#22)
* next 9.3 with preview mode * Fix post preview redirect and remove un-used items Co-authored-by: JJ Kasper <jj@jjsweb.site>
- Loading branch information
Showing
11 changed files
with
501 additions
and
135 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,5 @@ yarn-error.log* | |
|
||
.blog_index_data | ||
.blog_index_data_previews | ||
|
||
.now |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next' | ||
|
||
export default (req: NextApiRequest, res: NextApiResponse) => { | ||
if (req.query.slug) { | ||
res.clearPreviewData() | ||
res.writeHead(307, { Location: `/blog/${req.query.slug}` }) | ||
res.end() | ||
} else { | ||
res.clearPreviewData() | ||
res.writeHead(307, { Location: `/blog` }) | ||
res.end() | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next' | ||
import getPageData from '../../lib/notion/getPageData' | ||
import getBlogIndex from '../../lib/notion/getBlogIndex' | ||
import { getBlogLink } from '../../lib/blog-helpers' | ||
|
||
export default async (req: NextApiRequest, res: NextApiResponse) => { | ||
if (typeof req.query.token !== 'string') { | ||
return res.status(401).json({ message: 'invalid token' }) | ||
} | ||
if (req.query.token !== process.env.NOTION_TOKEN) { | ||
return res.status(404).json({ message: 'not authorized' }) | ||
} | ||
|
||
if (typeof req.query.slug !== 'string') { | ||
return res.status(401).json({ message: 'invalid slug' }) | ||
} | ||
const postsTable = await getBlogIndex() | ||
const post = postsTable[req.query.slug] | ||
|
||
if (!post) { | ||
console.log(`Failed to find post for slug: ${req.query.slug}`) | ||
return { | ||
props: { | ||
redirect: '/blog', | ||
}, | ||
revalidate: 5, | ||
} | ||
} | ||
|
||
const postData = await getPageData(post.id) | ||
|
||
if (!postData) { | ||
return res.status(401).json({ message: 'Invalid slug' }) | ||
} | ||
|
||
res.setPreviewData({}) | ||
res.writeHead(307, { Location: getBlogLink(post.Slug) }) | ||
res.end() | ||
} |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { NextApiRequest, NextApiResponse } from 'next' | ||
import getPageData from '../../lib/notion/getPageData' | ||
import getBlogIndex from '../../lib/notion/getBlogIndex' | ||
|
||
export default async (req: NextApiRequest, res: NextApiResponse) => { | ||
if (typeof req.query.token !== 'string') { | ||
return res.status(401).json({ message: 'invalid token' }) | ||
} | ||
if (req.query.token !== process.env.NOTION_TOKEN) { | ||
return res.status(404).json({ message: 'not authorized' }) | ||
} | ||
|
||
const postsTable = await getBlogIndex() | ||
|
||
if (!postsTable) { | ||
return res.status(401).json({ message: 'Failed to fetch posts' }) | ||
} | ||
|
||
res.setPreviewData({}) | ||
res.writeHead(307, { Location: `/blog` }) | ||
res.end() | ||
} |
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.