From 65a51549f3881d8d3dd9b7085a5b130d166c9580 Mon Sep 17 00:00:00 2001 From: randxie Date: Sat, 27 Apr 2024 21:25:33 -0700 Subject: [PATCH] add movie review --- app/blog/page.tsx | 2 +- app/random/[...slug]/page.tsx | 131 ++++++++++++++++++ app/random/page.tsx | 30 ++++ app/random/page/[page]/page.tsx | 34 +++++ app/tag-data.json | 2 +- contentlayer.config.ts | 39 +++++- data/headerNavLinks.ts | 7 +- data/random/2024-04-27-let-life-slow-down.mdx | 21 +++ layouts/ListLayout.tsx | 18 ++- 9 files changed, 271 insertions(+), 13 deletions(-) create mode 100644 app/random/[...slug]/page.tsx create mode 100644 app/random/page.tsx create mode 100644 app/random/page/[page]/page.tsx create mode 100644 data/random/2024-04-27-let-life-slow-down.mdx diff --git a/app/blog/page.tsx b/app/blog/page.tsx index 06f6f0d..8aec90c 100644 --- a/app/blog/page.tsx +++ b/app/blog/page.tsx @@ -24,7 +24,7 @@ export default function BlogPage() { posts={posts} initialDisplayPosts={initialDisplayPosts} pagination={pagination} - title="All Posts" + title="Tags" /> ) } diff --git a/app/random/[...slug]/page.tsx b/app/random/[...slug]/page.tsx new file mode 100644 index 0000000..b0647d8 --- /dev/null +++ b/app/random/[...slug]/page.tsx @@ -0,0 +1,131 @@ +import 'css/prism.css' +import 'katex/dist/katex.css' + +import PageTitle from '@/components/PageTitle' +import { components } from '@/components/MDXComponents' +import { MDXLayoutRenderer } from 'pliny/mdx-components' +import { sortPosts, coreContent, allCoreContent } from 'pliny/utils/contentlayer' +import { allAuthors, allRandomThoughts } from 'contentlayer/generated' +import type { Authors, RandomThoughts } from 'contentlayer/generated' +import PostSimple from '@/layouts/PostSimple' +import PostLayout from '@/layouts/PostLayout' +import PostBanner from '@/layouts/PostBanner' +import { Metadata } from 'next' +import siteMetadata from '@/data/siteMetadata' + +const defaultLayout = 'PostLayout' +const layouts = { + PostSimple, + PostLayout, + PostBanner, +} + +export async function generateMetadata({ + params, +}: { + params: { slug: string[] } +}): Promise { + const slug = decodeURI(params.slug.join('/')) + const post = allRandomThoughts.find((p) => p.slug === slug) + const authorList = post?.authors || ['default'] + const authorDetails = authorList.map((author) => { + const authorResults = allAuthors.find((p) => p.slug === author) + return coreContent(authorResults as Authors) + }) + if (!post) { + return + } + + const publishedAt = new Date(post.date).toISOString() + const modifiedAt = new Date(post.lastmod || post.date).toISOString() + const authors = authorDetails.map((author) => author.name) + let imageList = [siteMetadata.socialBanner] + if (post.images) { + imageList = typeof post.images === 'string' ? [post.images] : post.images + } + const ogImages = imageList.map((img) => { + console.log(img) + return { + url: img.includes('http') ? img : siteMetadata.siteUrl + img, + } + }) + + return { + title: post.title, + description: post.summary, + openGraph: { + title: post.title, + description: post.summary, + siteName: siteMetadata.title, + locale: 'en_US', + type: 'article', + publishedTime: publishedAt, + modifiedTime: modifiedAt, + url: './', + images: ogImages, + authors: authors.length > 0 ? authors : [siteMetadata.author], + }, + twitter: { + card: 'summary_large_image', + title: post.title, + description: post.summary, + images: imageList, + }, + } +} + +export const generateStaticParams = async () => { + const paths = allRandomThoughts.map((p) => ({ slug: p.slug.split('/') })) + + return paths +} + +export default async function Page({ params }: { params: { slug: string[] } }) { + const slug = decodeURI(params.slug.join('/')) + // Filter out drafts in production + const sortedCoreContents = allCoreContent(sortPosts(allRandomThoughts)) + const postIndex = sortedCoreContents.findIndex((p) => p.slug === slug) + if (postIndex === -1) { + return ( +
+ + Under Construction{' '} + + 🚧 + + +
+ ) + } + + const prev = sortedCoreContents[postIndex + 1] + const next = sortedCoreContents[postIndex - 1] + const post = allRandomThoughts.find((p) => p.slug === slug) as RandomThoughts + const authorList = post?.authors || ['default'] + const authorDetails = authorList.map((author) => { + const authorResults = allAuthors.find((p) => p.slug === author) + return coreContent(authorResults as Authors) + }) + const mainContent = coreContent(post) + const jsonLd = post.structuredData + jsonLd['author'] = authorDetails.map((author) => { + return { + '@type': 'Person', + name: author.name, + } + }) + + const Layout = layouts[post.layout || defaultLayout] + + return ( + <> +