Files
sage-home/lib/lines.ts
砂糖 99ce2b7fb8 feat: 更新网站配置和内容,优化国际化设置
refactor: 重构产线页面和路由,移除无用代码
style: 调整内容格式和样式,统一中英文标点
docs: 更新产品描述和元数据,完善多语言支持
2026-01-26 16:22:07 +08:00

30 lines
1.2 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');
// console.log(fileContent);
const { data: frontmatter, content } = matter(fileContent);
console.log(frontmatter);
workShops.push(frontmatter as Line);
}
console.log(workShops, files);
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;
}