Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't display unpublished articles #126

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/issue/[issueNumber]/[articleSlug]/not-found.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Link from 'next/link'

export default function NotFound() {
return (
<div className="flex justify-center w-full">
<h2>Article not found!</h2>
</div>
)
}
10 changes: 8 additions & 2 deletions db/queries/articles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
wrapCache,
} from "../common";
import { format } from 'date-fns';
import { notFound } from 'next/navigation';

export const UNCATEGORIZED_CATEGORY: Category = { id: UNCATEGORIZED_CATEGORY_ID, name: UNCATEGORIZED_CATEGORY_NAME, slug: UNCATEGORIZED_CATEGORY_SLUG };

Expand Down Expand Up @@ -182,10 +183,15 @@ export const getArticle = async(slug: string): Promise<ArticlePage> => {
.limit(1);

if (!Array.isArray(article) || article.length === 0)
throw new Error('Article not found!');
notFound();

if (!article[0].markdown)
throw new Error('Article missing content!');
notFound();

// Don't render unpublished articles
if (article[0].publishedAt == null)
notFound();
// throw new Error('Article not found!');

// attempt to get audio
const audioUri = await db.select({
Expand Down
Loading