refactor(about): 重构关于页面路由为静态路径
将关于页面的查询参数路由改为静态路径结构,如/about/company 更新i18n消息中的链接路径 添加新的[section]页面处理逻辑 优化静态生成参数和错误处理
This commit is contained in:
@@ -72,51 +72,6 @@ async function getMDXContent(locale: string, section: string): Promise<BlogPost>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析MDX内容,提取frontmatter和正文
|
||||
*/
|
||||
function parseMDXContent(content: string): {
|
||||
frontmatter: Record<string, any>
|
||||
content: string
|
||||
} {
|
||||
// 匹配frontmatter的正则表达式(---开头和结尾)
|
||||
const frontmatterRegex = /^---\s*[\r\n]([\s\S]*?)[\r\n]---\s*[\r\n]/;
|
||||
const match = frontmatterRegex.exec(content);
|
||||
|
||||
let frontmatter: Record<string, any> = {};
|
||||
let postContent = content;
|
||||
|
||||
if (match && match[1]) {
|
||||
// 提取frontmatter部分并解析
|
||||
const frontmatterStr = match[1];
|
||||
postContent = content.slice(match[0].length);
|
||||
|
||||
// 解析frontmatter的每一行
|
||||
const lines = frontmatterStr.split(/[\r\n]+/);
|
||||
lines.forEach(line => {
|
||||
// 跳过空行和注释
|
||||
if (!line.trim() || line.trim().startsWith('#')) return;
|
||||
|
||||
// 分割键值对(支持值中有冒号的情况)
|
||||
const colonIndex = line.indexOf(':');
|
||||
if (colonIndex === -1) return;
|
||||
|
||||
const key = line.substring(0, colonIndex).trim();
|
||||
let value = line.substring(colonIndex + 1).trim();
|
||||
|
||||
// 移除值的引号(如果有)
|
||||
if ((value.startsWith('"') && value.endsWith('"')) ||
|
||||
(value.startsWith("'") && value.endsWith("'"))) {
|
||||
value = value.substring(1, value.length - 1);
|
||||
}
|
||||
|
||||
frontmatter[key] = value;
|
||||
});
|
||||
}
|
||||
|
||||
return { frontmatter, content: postContent };
|
||||
}
|
||||
|
||||
|
||||
export async function generateMetadata({
|
||||
params,
|
||||
|
||||
Reference in New Issue
Block a user