upstream #1

Merged
jblu merged 1007 commits from upstream into main 2024-11-04 22:35:57 -06:00
Showing only changes of commit 598623e025 - Show all commits

View File

@ -4,7 +4,7 @@ import 'katex/dist/katex.css'
import PageTitle from '@/components/PageTitle' import PageTitle from '@/components/PageTitle'
import { components } from '@/components/MDXComponents' import { components } from '@/components/MDXComponents'
import { MDXLayoutRenderer } from 'pliny/mdx-components' import { MDXLayoutRenderer } from 'pliny/mdx-components'
import { sortPosts, coreContent } from 'pliny/utils/contentlayer' import { sortPosts, coreContent, allCoreContent } from 'pliny/utils/contentlayer'
import { allBlogs, allAuthors } from 'contentlayer/generated' import { allBlogs, allAuthors } from 'contentlayer/generated'
import type { Authors, Blog } from 'contentlayer/generated' import type { Authors, Blog } from 'contentlayer/generated'
import PostSimple from '@/layouts/PostSimple' import PostSimple from '@/layouts/PostSimple'
@ -13,7 +13,6 @@ import PostBanner from '@/layouts/PostBanner'
import { Metadata } from 'next' import { Metadata } from 'next'
import siteMetadata from '@/data/siteMetadata' import siteMetadata from '@/data/siteMetadata'
const isProduction = process.env.NODE_ENV === 'production'
const defaultLayout = 'PostLayout' const defaultLayout = 'PostLayout'
const layouts = { const layouts = {
PostSimple, PostSimple,
@ -82,11 +81,25 @@ export const generateStaticParams = async () => {
export default async function Page({ params }: { params: { slug: string[] } }) { export default async function Page({ params }: { params: { slug: string[] } }) {
const slug = decodeURI(params.slug.join('/')) const slug = decodeURI(params.slug.join('/'))
const sortedPosts = sortPosts(allBlogs) as Blog[] // Filter out drafts in production
const postIndex = sortedPosts.findIndex((p) => p.slug === slug) const sortedCoreContents = allCoreContent(sortPosts(allBlogs))
const prev = coreContent(sortedPosts[postIndex + 1]) const postIndex = sortedCoreContents.findIndex((p) => p.slug === slug)
const next = coreContent(sortedPosts[postIndex - 1]) if (postIndex === -1) {
const post = sortedPosts.find((p) => p.slug === slug) as Blog return (
<div className="mt-24 text-center">
<PageTitle>
Under Construction{' '}
<span role="img" aria-label="roadwork sign">
🚧
</span>
</PageTitle>
</div>
)
}
const prev = sortedCoreContents[postIndex + 1]
const next = sortedCoreContents[postIndex - 1]
const post = allBlogs.find((p) => p.slug === slug) as Blog
const authorList = post?.authors || ['default'] const authorList = post?.authors || ['default']
const authorDetails = authorList.map((author) => { const authorDetails = authorList.map((author) => {
const authorResults = allAuthors.find((p) => p.slug === author) const authorResults = allAuthors.find((p) => p.slug === author)
@ -104,17 +117,6 @@ export default async function Page({ params }: { params: { slug: string[] } }) {
const Layout = layouts[post.layout || defaultLayout] const Layout = layouts[post.layout || defaultLayout]
return ( return (
<>
{isProduction && post && 'draft' in post && post.draft === true ? (
<div className="mt-24 text-center">
<PageTitle>
Under Construction{' '}
<span role="img" aria-label="roadwork sign">
🚧
</span>
</PageTitle>
</div>
) : (
<> <>
<script <script
type="application/ld+json" type="application/ld+json"
@ -124,7 +126,5 @@ export default async function Page({ params }: { params: { slug: string[] } }) {
<MDXLayoutRenderer code={post.body.code} components={components} toc={post.toc} /> <MDXLayoutRenderer code={post.body.code} components={components} toc={post.toc} />
</Layout> </Layout>
</> </>
)}
</>
) )
} }