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