Skip to content

Commit

Permalink
Call notFound where post was not found
Browse files Browse the repository at this point in the history
  • Loading branch information
zoul committed Feb 16, 2023
1 parent 7c47788 commit 9f1daba
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/[...path]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from "shared/site-data";
import { markdownToHTML } from "shared/utils";
import { Metadata } from "next";
import { notFound } from "next/navigation";

type Params = {
path: string[];
Expand All @@ -19,7 +20,7 @@ type Props = {
};

const Post = ({ params }: Props) => {
const post = postForPath(params.path);
const post = postForPath(params.path) || notFound();
const authors = getAllAuthors();
const author = authors.find((a) => a.id === post.authorId)!;
const otherPosts = getAllBlogPosts()
Expand Down Expand Up @@ -95,7 +96,7 @@ const PostBody = ({ post, author }: { post: BlogPost; author: Author }) => {
const postForPath = (path: string[]) => {
const mergedPath = "/" + path.join("/");
const allPosts = [...getAllBlogPosts(), ...getAllPressReleases()];
return allPosts.find((post) => post.path === mergedPath)!;
return allPosts.find((post) => post.path === mergedPath);
};

export async function generateStaticParams(): Promise<Params[]> {
Expand All @@ -106,7 +107,7 @@ export async function generateStaticParams(): Promise<Params[]> {
}

export async function generateMetadata({ params }: Props): Promise<Metadata> {
const post = postForPath(params.path);
const post = postForPath(params.path) || notFound();
return {
title: post.title,
openGraph: {
Expand Down

0 comments on commit 9f1daba

Please sign in to comment.