소스 검색

fix title

ruki 1 개월 전
부모
커밋
c0dc68b615

+ 15 - 6
docs/.vitepress/config.mts

@@ -16,14 +16,23 @@ export default defineConfig({
 
   markdown: {
     config(md) {
-      // Add title from frontmatter plugin FIRST, before other plugins
-      // Process all files - the function will check if title should be added
+      // Add title from frontmatter plugin FIRST, before groupIconMdPlugin
+      // Only process files in posts directory
       const originalParse = md.parse.bind(md)
       md.parse = (src: string, env: any) => {
-        // Always process - addTitleFromFrontmatter will check if title exists
-        // and content doesn't already start with H1
-        const processedSrc = addTitleFromFrontmatter(src)
-        return originalParse(processedSrc, env)
+        // Check if this is a posts file
+        const filePath = env?.relativePath || 
+                        env?.file?.relativePath || 
+                        env?.path?.relativePath ||
+                        (env?.id ? String(env.id) : '') ||
+                        ''
+        
+        // Only process posts files
+        if (filePath && filePath.includes('/posts/')) {
+          const processedSrc = addTitleFromFrontmatter(src)
+          return originalParse(processedSrc, env)
+        }
+        return originalParse(src, env)
       }
       
       md.use(groupIconMdPlugin, {

+ 2 - 1
docs/.vitepress/plugins/add-title.ts

@@ -39,8 +39,9 @@ export function addTitleFromFrontmatter(src: string): string {
   }
 
   // Add title as H1 after frontmatter
-  // Escape any markdown special characters in the title to prevent parsing issues
+  // Replace newlines and ensure title is properly formatted
   const escapedTitle = title.replace(/\n/g, ' ').trim()
+  
   return frontmatterMatch[0] + `# ${escapedTitle}\n\n` + contentAfterFrontmatter
 }
 

+ 1 - 1
docs/.vitepress/theme/blog-data.js

@@ -1,6 +1,6 @@
 export const posts = [
   {
-    "title": "Xmake v3.0.5 preview, Multi-row progress output, XML module, async OS APIs and Swift interop",
+    "title": "Xmake v3.0.5 preview, Multi-row progress, XML module and Swift interop",
     "url": "/posts/xmake-update-v3.0.5",
     "date": {
       "time": 1763380800000,

+ 1 - 1
docs/.vitepress/theme/zh-blog-data.js

@@ -1,6 +1,6 @@
 export const posts = [
   {
-    "title": "Xmake v3.0.5 预览多行进度输出、XML 模块、异步 OS API 和 Swift 互操作",
+    "title": "Xmake v3.0.5 预览多行进度输出、XML 模块、异步 OS API 和 Swift 互操作",
     "url": "/zh/posts/xmake-update-v3.0.5",
     "date": {
       "time": 1763380800000,

+ 1 - 1
docs/posts/xmake-update-v3.0.5.md

@@ -1,5 +1,5 @@
 ---
-title: Xmake v3.0.5 preview, Multi-row progress output, XML module, async OS APIs and Swift interop
+title: Xmake v3.0.5 preview, Multi-row progress, XML module and Swift interop
 tags: [xmake, swift, xml, async, progress, toolchain, cuda]
 date: 2025-11-17
 author: Ruki

+ 1 - 1
docs/zh/posts/xmake-update-v3.0.5.md

@@ -1,5 +1,5 @@
 ---
-title: Xmake v3.0.5 预览多行进度输出、XML 模块、异步 OS API 和 Swift 互操作
+title: Xmake v3.0.5 预览多行进度输出、XML 模块、异步 OS API 和 Swift 互操作
 tags: [xmake, swift, xml, async, progress, toolchain, cuda]
 date: 2025-11-17
 author: Ruki