Skip to content

Commit

Permalink
refactor: content within the blog section
Browse files Browse the repository at this point in the history
  • Loading branch information
ashgw committed Feb 13, 2024
1 parent 3eed2bf commit 3c96711
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 74 deletions.
5 changes: 2 additions & 3 deletions src/app/(pages)/blog/[post]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { Suspense } from 'react';
import { Metadata } from 'next';
import { notFound } from 'next/navigation';
import { getBlogPost } from '@/app/actions/blog';
import { getBlogPosts } from '@/app/api/blogs/content';
import { getBlogPosts, getBlogPost } from '../content';
import { pub } from '@/lib/env';
import LoadingScreen from '../loading';
import LoadingScreen from '@/app/components/reusables/loading-screen';
import BlogSection from '@/app/components/blog/blog-section';

type RouteParams = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import path from 'path';
import fm from 'front-matter';
import type { MDXData, BlogData } from '@/lib/types/mdx';
import { BLOG_CONTENT_PATH } from '@/lib/constants';
import type { Maybe } from '@/lib/types/global';

function parseMDX(content: string): MDXData {
return fm(content) as MDXData;
Expand Down Expand Up @@ -50,3 +51,10 @@ async function getMDXData(dir: string): Promise<BlogData[]> {
export async function getBlogPosts(): Promise<BlogData[]> {
return getMDXData(path.join(process.cwd(), BLOG_CONTENT_PATH));
}

export async function getBlogPost(slug: string): Promise<Maybe<BlogData>> {
// TODO: optimize
const blogs = await getBlogPosts();
const blogPost = blogs.find((p) => p?.filenameSlug === slug);
return blogPost;
}
2 changes: 1 addition & 1 deletion src/app/(pages)/blog/loading.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import LoadingScreen from '@/app/loading';
import LoadingScreen from '@/app/components/reusables/loading-screen';
export default LoadingScreen;
2 changes: 1 addition & 1 deletion src/app/(pages)/blog/page.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Suspense } from 'react';
import LoadingScreen from '@/app/components/reusables/loading-screen';
import BlogPosts from '@/app/components/blog/blog-posts';
import { getBlogPosts } from '@/app/actions/blog';
import { getBlogPosts } from './content';
import { notFound } from 'next/navigation';
export default async function BlogPage() {
const blogPosts = await getBlogPosts();
Expand Down
38 changes: 0 additions & 38 deletions src/app/actions/blog.ts

This file was deleted.

31 changes: 0 additions & 31 deletions src/app/api/blogs/route.ts

This file was deleted.

0 comments on commit 3c96711

Please sign in to comment.