This commit is contained in:
砂糖
2026-01-24 16:54:44 +08:00
commit 70f337bb92
186 changed files with 23792 additions and 0 deletions

27
lib/workshop.ts Normal file
View File

@@ -0,0 +1,27 @@
import { WorkShop } from '@/types/workShop';
import fs from 'fs';
import matter from 'gray-matter';
import path from 'path';
// 获取指定语言的所有车间
export async function getWorkShops(locale: string): Promise<WorkShop[]> {
const contentPath = path.join(process.cwd(), `content/workshop/${locale}`);
console.log(contentPath);
const files = fs.readdirSync(contentPath);
const workShops: WorkShop[] = [];
for (const file of files.map((file) => file.replace('.mdx', ''))) {
const contentPath = path.join(process.cwd(), `content/workshop/${locale}/${file}.mdx`);
const fileContent = fs.readFileSync(contentPath, 'utf8');
const { data: frontmatter, content } = matter(fileContent);
workShops.push(frontmatter as WorkShop);
}
return workShops;
}
// 获取特定车间的内容
export async function getWorkShop(locale: string, title: string): Promise<WorkShop> {
const contentPath = path.join(process.cwd(), `content/workshop/${locale}/${title}.mdx`);
const fileContent = fs.readFileSync(contentPath, 'utf8');
const { data: frontmatter, content } = matter(fileContent);
return frontmatter as WorkShop;
}