-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into next-windows
- Loading branch information
Showing
34 changed files
with
393 additions
and
315 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 |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { notFound } from "next/navigation"; | ||
import Image from "next/image"; | ||
import { format, parseISO } from "date-fns"; | ||
import { MDXRemote } from "next-mdx-remote/rsc"; | ||
import { getBlogPosts } from "@/utils/blog"; | ||
import type { Metadata } from "next"; | ||
import { Share } from "../_components/Share"; | ||
import { ReadyToGetStarted } from "@/components/ReadyToGetStarted"; | ||
import { calculateReadingTime } from "@/utils/readTime"; | ||
|
||
interface PostProps { | ||
params: { | ||
slug: string; | ||
}; | ||
} | ||
|
||
export async function generateMetadata({ | ||
params, | ||
}: PostProps): Promise<Metadata | undefined> { | ||
let post = getBlogPosts().find((post) => post.slug === params.slug); | ||
if (!post) { | ||
return; | ||
} | ||
|
||
let { title, publishedAt: publishedTime, description, image } = post.metadata; | ||
let ogImage = `${process.env.NEXT_PUBLIC_URL}${image}`; | ||
|
||
return { | ||
title, | ||
description, | ||
openGraph: { | ||
title, | ||
description, | ||
type: "article", | ||
publishedTime, | ||
url: `${process.env.NEXT_PUBLIC_URL}/blog/${post.slug}`, | ||
images: [ | ||
{ | ||
url: ogImage, | ||
}, | ||
], | ||
}, | ||
twitter: { | ||
card: "summary_large_image", | ||
title, | ||
description, | ||
images: [ogImage], | ||
}, | ||
}; | ||
} | ||
|
||
export default async function PostPage({ params }: PostProps) { | ||
const post = getBlogPosts().find((post) => post.slug === params.slug); | ||
|
||
if (!post) { | ||
notFound(); | ||
} | ||
|
||
const readingTime = calculateReadingTime(post.content); | ||
|
||
return ( | ||
<> | ||
<article className="py-8 prose mx-auto "> | ||
{post.metadata.image && ( | ||
<div className="relative mb-12 h-[345px] w-full"> | ||
<Image | ||
className="m-0 w-full rounded-lg object-contain sm:object-cover" | ||
src={post.metadata.image} | ||
alt={post.metadata.title} | ||
fill | ||
priority | ||
/> | ||
</div> | ||
)} | ||
|
||
<div className="wrapper"> | ||
<header> | ||
<h1 className="mb-2">{post.metadata.title}</h1> | ||
<p className="space-x-1 text-xs text-gray-500"> | ||
<span> | ||
{format(parseISO(post.metadata.publishedAt), "MMMM dd, yyyy")} | ||
</span> | ||
<span>—</span> | ||
<span>{readingTime} min read</span> | ||
</p> | ||
</header> | ||
<hr className="my-6" /> | ||
<MDXRemote source={post.content} /> | ||
<Share post={post} /> | ||
</div> | ||
</article> | ||
<div className="wrapper mb-4"> | ||
<ReadyToGetStarted /> | ||
</div> | ||
</> | ||
); | ||
} |
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,59 @@ | ||
"use client"; | ||
|
||
import toast from "react-hot-toast"; | ||
import { useState } from "react"; | ||
|
||
interface ShareProps { | ||
post: { | ||
slug: string; | ||
metadata: { | ||
title: string; | ||
}; | ||
}; | ||
} | ||
|
||
export function Share({ post }: ShareProps) { | ||
const shareUrl = `${process.env.NEXT_PUBLIC_URL}/blog/${post.slug}`; | ||
const [copied, setCopied] = useState(false); | ||
|
||
return ( | ||
<> | ||
<div className="mt-6 py-6 px-3 bg-gray-100 text-center rounded-xl"> | ||
<h3 className="mb-2 mt-0 text-lg font-semibold">Share this post</h3> | ||
<div className="flex justify-center gap-4"> | ||
<a | ||
href={`https://twitter.com/intent/tweet?text=${encodeURIComponent( | ||
post.metadata.title | ||
)}&url=${encodeURIComponent(shareUrl)}`} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
className="text-lg text-gray-600 hover:text-blue-500 hover:underline" | ||
> | ||
</a> | ||
<a | ||
href={`https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent( | ||
shareUrl | ||
)}`} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
className="text-lg text-gray-600 hover:text-blue-700 hover:underline" | ||
> | ||
</a> | ||
<button | ||
onClick={() => { | ||
navigator.clipboard.writeText(shareUrl); | ||
toast.success("Link copied to clipboard"); | ||
setCopied(true); | ||
setTimeout(() => setCopied(false), 2000); | ||
}} | ||
className="text-lg text-gray-600 hover:text-gray-900 underline" | ||
> | ||
{copied ? "Link copied" : "Copy Link"} | ||
</button> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
} |
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
This file was deleted.
Oops, something went wrong.
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.