瀏覽代碼

improve posts

ruki 2 周之前
父節點
當前提交
95832c6288
共有 2 個文件被更改,包括 21 次插入2 次删除
  1. 15 2
      docs/.vitepress/theme/index.ts
  2. 6 0
      docs/.vitepress/theme/styles.css

+ 15 - 2
docs/.vitepress/theme/index.ts

@@ -1,5 +1,5 @@
 import Theme from 'vitepress/theme'
-import { h, computed } from 'vue'
+import { h, computed, watch } from 'vue'
 import VPDoc from './components/VPDoc.vue'
 import AIAssistant from './components/AIAssistant.vue'
 import WWAds from './components/WWAds.vue'
@@ -35,8 +35,21 @@ export default {
              page.value.relativePath.startsWith('zh/') || 
              page.value.filePath.includes('/zh/')
     })
+    const isPost = computed(() => {
+      return page.value.filePath.includes('posts/')
+    })
+
+    if (typeof window !== 'undefined') {
+      watch(isPost, (value) => {
+        if (value) {
+          document.body.classList.add('is-post')
+        } else {
+          document.body.classList.remove('is-post')
+        }
+      }, { immediate: true })
+    }
 
-    return h(Theme.Layout, null, {
+    return h(Theme.Layout, { class: { 'is-post': isPost.value } }, {
       'doc-content-before': () => h(VPDoc),
       'doc-after': () => {
         if (isZh.value) {

+ 6 - 0
docs/.vitepress/theme/styles.css

@@ -97,3 +97,9 @@
     display: none;
   }
 }
+
+/* Hide right sidebar carbon ads on post pages */
+body.is-post .VPDocAside .VPDocAsideCarbonAds,
+body.is-post .VPDocAside .VPCarbonAds {
+  display: none !important;
+}