feat: implement project fetching and markdown rendering for enhanced project display
This commit is contained in:
26
app/api/projects/route.tsx
Normal file
26
app/api/projects/route.tsx
Normal file
@@ -0,0 +1,26 @@
|
||||
import {NextResponse} from 'next/server';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import matter from 'gray-matter';
|
||||
|
||||
export async function GET() {
|
||||
const projectsDirectory = path.join(process.cwd(), 'public/projects');
|
||||
const filenames = fs.readdirSync(projectsDirectory);
|
||||
|
||||
console.log('Filenames:', filenames);
|
||||
|
||||
const projects = filenames.map((filename) => {
|
||||
const filePath = path.join(projectsDirectory, filename);
|
||||
const fileContents = fs.readFileSync(filePath, 'utf8');
|
||||
const {data} = matter(fileContents);
|
||||
|
||||
return {
|
||||
id: data.id,
|
||||
title: data.title,
|
||||
description: data.description,
|
||||
slug: filename.replace('.md', ''),
|
||||
};
|
||||
});
|
||||
|
||||
return NextResponse.json(projects);
|
||||
}
|
||||
Reference in New Issue
Block a user