added case-study slug framework
All checks were successful
Build and Deploy NextJS SculptedArc Website / build-and-deploy (push) Successful in 1m10s

This commit is contained in:
2026-06-22 19:24:13 +01:00
parent ef8d90651e
commit ea12adf484
7 changed files with 814 additions and 38 deletions

33
lib/case-study.ts Normal file
View File

@@ -0,0 +1,33 @@
// src/lib/blog.ts
import fs from 'fs';
import path from 'path';
import matter from 'gray-matter';
import { remark } from 'remark';
import html from 'remark-html';
const postsDirectory = path.join(process.cwd(), 'content/case-studies');
export async function getPostBySlug(slug: string) {
const fullPath = path.join(postsDirectory, `${slug}.md`);
// Guard against file system traversal attacks or missing files
if (!fs.existsSync(fullPath)) {
return null;
}
const fileContents = fs.readFileSync(fullPath, 'utf8');
// Use gray-matter to parse the study metadata section
const { data, content } = matter(fileContents);
// Use remark to convert markdown into HTML string
const processedContent = await remark().use(html).process(content);
const contentHtml = processedContent.toString();
return {
slug,
contentHtml,
title: data.title || 'Untitled Study',
...data,
};
}