shivam + claude changes
All checks were successful
Deploy Website / build-and-deploy (push) Successful in 28s
All checks were successful
Deploy Website / build-and-deploy (push) Successful in 28s
This commit is contained in:
15
lib/mdx.ts
15
lib/mdx.ts
@@ -10,7 +10,6 @@ export type PostMetadata = {
|
||||
description: string;
|
||||
slug: string;
|
||||
tags?: string[];
|
||||
[key: string]: any;
|
||||
};
|
||||
|
||||
export type Post = {
|
||||
@@ -27,8 +26,20 @@ export function getPostSlugs() {
|
||||
|
||||
export function getPostBySlug(slug: string): Post {
|
||||
const realSlug = slug.replace(/\.mdx$/, '');
|
||||
|
||||
if (/[\/\\]|\.\./.test(realSlug)) {
|
||||
throw new Error(`Invalid slug: ${realSlug}`);
|
||||
}
|
||||
|
||||
const fullPath = path.join(postsDirectory, `${realSlug}.mdx`);
|
||||
const fileContents = fs.readFileSync(fullPath, 'utf8');
|
||||
|
||||
let fileContents: string;
|
||||
try {
|
||||
fileContents = fs.readFileSync(fullPath, 'utf8');
|
||||
} catch {
|
||||
throw new Error(`Post not found: ${realSlug}`);
|
||||
}
|
||||
|
||||
const { data, content } = matter(fileContents);
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user