clone init

This commit is contained in:
2026-01-16 21:47:58 +01:00
parent ffbb240a23
commit ce1a73f2bc
160 changed files with 64257 additions and 9 deletions

34
lib/pages.ts Normal file
View File

@@ -0,0 +1,34 @@
import fs from 'fs';
import path from 'path';
import matter from 'gray-matter';
export interface PageFrontmatter {
title: string;
excerpt: string;
featuredImage: string | null;
locale: string;
}
export interface PageMdx {
slug: string;
frontmatter: PageFrontmatter;
content: string;
}
export async function getPageBySlug(slug: string, locale: string): Promise<PageMdx | null> {
const pagesDir = path.join(process.cwd(), 'data', 'pages', locale);
const filePath = path.join(pagesDir, `${slug}.mdx`);
if (!fs.existsSync(filePath)) {
return null;
}
const fileContent = fs.readFileSync(filePath, 'utf8');
const { data, content } = matter(fileContent);
return {
slug,
frontmatter: data as PageFrontmatter,
content,
};
}