Skip to content

Commit

Permalink
add generatestaticparams
Browse files Browse the repository at this point in the history
  • Loading branch information
kchenturtles committed Dec 24, 2023
1 parent 25d6043 commit 2333d47
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 180 deletions.
11 changes: 7 additions & 4 deletions app/posts/page.tsx → app/blog/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

import { getAllPosts } from "../../lib/api";
import { getAllPosts, getPostSlugs, getPostBySlug } from "../../lib/api";
import PostPreview from "../../components/postPreview";
import PageTitle from "../../components/page-title";
import styles from "./styles.module.css";

export default function Posts() {

const posts = getAllPosts(["title", "date", "excerpt", "slug"]);

return (
Expand All @@ -13,11 +14,12 @@ export default function Posts() {
<div className="container">
<PageTitle>All Posts</PageTitle>
<div className = {styles.posts}>
{posts.map((post) => (
{posts.map((post) => (
<div>
<PostPreview post={post} />
<PostPreview post= { post } />
</div>
))}
))
}
</div>
</div>

Expand All @@ -26,3 +28,4 @@ export default function Posts() {
</div>
);
}

13 changes: 11 additions & 2 deletions app/posts/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@ import styles from "./styles.module.css";
import Image from "next-image-export-optimizer";
import Link from "next/link";

export default async function Page({ params }: { params: { slug: string } }) {
export async function generateStaticParams() {
const posts = getPostSlugs();
return posts.map((post) => ({
slug: post,
}));
}

export default async function Page({ params }: { params: { slug: string }}) {

const { slug } = params;

const getPost = getPostBySlug(params.slug, ["title", "author", "content", "date"]);
const getPost = getPostBySlug(slug, ["title", "author", "content", "date"]);

const content = await markdownToHtml(getPost["content"] || "");

Expand Down
172 changes: 0 additions & 172 deletions app/posts/styles.module.css

This file was deleted.

2 changes: 1 addition & 1 deletion components/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const Navbar = () => {
},
{label: "Awards", to: "/awards"},
{ label: "Our Team", to: "/team" },
{ label: "Build Blog", to: "/posts" },
{ label: "Build Blog", to: "/blog" },
{ label: "Sponsors", to: "/sponsors" },
{ label: "Gallery", to: "/gallery" },
{ label: "Contact", to: "/contact" },
Expand Down
3 changes: 2 additions & 1 deletion lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import * as fs from "fs";
import { join } from "path";
import matter from "gray-matter";

const postsDirectory = join(process.cwd(), "_posts");
const postsDirectory = "_posts";
//join("process.cwd()", "_posts");

export function getPostSlugs() {
return fs.readdirSync(postsDirectory);
Expand Down

0 comments on commit 2333d47

Please sign in to comment.