Browse Source

improve posts

ruki 1 week ago
parent
commit
0fc28fb079
3 changed files with 52 additions and 2 deletions
  1. 2 2
      docs/.vitepress/theme/components/VPSidebar.vue
  2. 25 0
      docs/config.ts
  3. 25 0
      docs/zh/config.ts

+ 2 - 2
docs/.vitepress/theme/components/VPSidebar.vue

@@ -80,9 +80,9 @@ watch(
       tabindex="-1"
     >
 
-      <!-- Show carbonAds at the top of left sidebar, only for non-post pages (API docs, etc.) -->
+      <!-- Show carbonAds at the top of left sidebar -->
       <VPDocAsideCarbonAds 
-        v-if="!isPost && theme.carbonAds" 
+        v-if="theme.carbonAds" 
         :carbon-ads="theme.carbonAds" 
       />
 

+ 25 - 0
docs/config.ts

@@ -1,6 +1,7 @@
 import { createRequire } from 'module'
 import { defineAdditionalConfig, type DefaultTheme } from 'vitepress'
 import { builtinModulesApiSidebarItems, extensionModulesApiSidebarItems } from './sidebar'
+import { posts } from './.vitepress/theme/blog-data.js'
 
 const require = createRequire(import.meta.url)
 const pkg = require('vitepress/package.json')
@@ -17,6 +18,7 @@ export default defineAdditionalConfig({
       '/api/description/': { base: '/api/description/', items: descriptionApiSidebar() },
       '/api/scripts/': { base: '/api/scripts/', items: scriptsApiSidebar() },
       '/examples/': { base: '/examples/', items: examplesSidebar() },
+      ...postsSidebar(),
     },
 
     editLink: {
@@ -67,6 +69,29 @@ function nav(): DefaultTheme.NavItem[] {
   ]
 }
 
+function postsSidebar(): Record<string, DefaultTheme.SidebarItem[]> {
+  const sidebar: Record<string, DefaultTheme.SidebarItem[]> = {}
+  for (let i = 0; i < posts.length; i++) {
+    const post = posts[i]
+    const next = i > 0 ? posts[i - 1] : null
+    const prev = i < posts.length - 1 ? posts[i + 1] : null
+    
+    const items = []
+    if (next) {
+      items.push({ text: 'Previous Post', link: next.url })
+    }
+    if (prev) {
+      items.push({ text: 'Next Post', link: prev.url })
+    }
+    items.push({ text: 'Return to Blog', link: '/blog/' })
+    
+    sidebar[post.url + '/'] = items
+    sidebar[post.url + '.html'] = items
+    sidebar[post.url] = items
+  }
+  return sidebar
+}
+
 function guideSidebar(): DefaultTheme.SidebarItem[] {
   return [
     {

+ 25 - 0
docs/zh/config.ts

@@ -1,6 +1,7 @@
 import { createRequire } from 'module'
 import { defineAdditionalConfig, type DefaultTheme } from 'vitepress'
 import { builtinModulesApiSidebarItems, extensionModulesApiSidebarItems } from '../sidebar'
+import { posts } from '../.vitepress/theme/zh-blog-data.js'
 
 const require = createRequire(import.meta.url)
 const pkg = require('vitepress/package.json')
@@ -19,6 +20,7 @@ export default defineAdditionalConfig({
       '/zh/api/description/': { base: '/zh/api/description/', items: descriptionApiSidebar() },
       '/zh/api/scripts/': { base: '/zh/api/scripts/', items: scriptsApiSidebar() },
       '/zh/examples/': { base: '/zh/examples/', items: examplesSidebar() },
+      ...postsSidebar(),
     },
 
     editLink: {
@@ -148,6 +150,29 @@ function nav(): DefaultTheme.NavItem[] {
   ]
 }
 
+function postsSidebar(): Record<string, DefaultTheme.SidebarItem[]> {
+  const sidebar: Record<string, DefaultTheme.SidebarItem[]> = {}
+  for (let i = 0; i < posts.length; i++) {
+    const post = posts[i]
+    const next = i > 0 ? posts[i - 1] : null
+    const prev = i < posts.length - 1 ? posts[i + 1] : null
+    
+    const items = []
+    if (next) {
+      items.push({ text: '上一篇', link: next.url })
+    }
+    if (prev) {
+      items.push({ text: '下一篇', link: prev.url })
+    }
+    items.push({ text: '返回博客', link: '/zh/blog/' })
+    
+    sidebar[post.url + '/'] = items
+    sidebar[post.url + '.html'] = items
+    sidebar[post.url] = items
+  }
+  return sidebar
+}
+
 function guideSidebar(): DefaultTheme.SidebarItem[] {
   return [
     {