Skip to content

Commit

Permalink
Added generateStaticParams and fixed build.
Browse files Browse the repository at this point in the history
  • Loading branch information
vegetableman committed Jan 12, 2024
1 parent b899254 commit ef5f2c1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
13 changes: 13 additions & 0 deletions app/blog/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import fs from 'fs'
import { getPostData } from '@/lib/posts'
import formatDate from '@/lib/format'
import Link from 'next/link'
import path from 'path'

type Params = {
slug: string
Expand Down Expand Up @@ -57,6 +59,17 @@ export async function generateMetadata({ params }: Props) {
}
}

export function generateStaticParams() {
const postsDirectory = path.join(process.cwd(), 'posts');
const fileNames = fs.readdirSync(postsDirectory)
return fileNames.map((fileName) => {
return {
slug: path.basename(fileName, '.md')
}
});
}


// -< Post >-
export default async function Post({ params }: Props) {
const postData: PostData = await getPostData(params.slug);
Expand Down
6 changes: 5 additions & 1 deletion app/get-demo/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ import Footer from "@/components/footer";
import Navbar from "@/components/navbar";
import { Work_Sans } from "next/font/google";
import { useSearchParams, useRouter } from 'next/navigation'
import { companies } from "../page";
import Image from "next/image";

const companies = [
{ file: 'companies/philippines.webp', name: 'Philippines chamber of commerce' },
{ file: 'companies/spd.webp', name: 'SPD Jobs inc' },
{ file: 'companies/cbrc.webp', name: 'CBRC' },
];

const workSans = Work_Sans({
weight: ['400', '500', '600'],
Expand Down
2 changes: 1 addition & 1 deletion app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Footer from '@/components/footer';
import Discover from '@/components/discover';
import Image from 'next/image';

export const companies = [
const companies = [
{ file: 'companies/philippines.webp', name: 'Philippines chamber of commerce' },
{ file: 'companies/spd.webp', name: 'SPD Jobs inc' },
{ file: 'companies/cbrc.webp', name: 'CBRC' },
Expand Down
7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"remark-html": "^16.0.1"
},
"devDependencies": {
"@types/luxon": "^3.4.0",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
Expand Down

0 comments on commit ef5f2c1

Please sign in to comment.