|
1 | 1 | <script lang="ts" setup> |
2 | 2 | import { useScrollLock } from '@vueuse/core' |
3 | 3 | import { inBrowser } from 'vitepress' |
4 | | -import { ref, watch } from 'vue' |
| 4 | +import { ref, watch, computed } from 'vue' |
5 | 5 | import { useLayout } from 'vitepress/dist/client/theme-default/composables/layout' |
6 | 6 | import VPSidebarGroup from 'vitepress/dist/client/theme-default/components/VPSidebarGroup.vue' |
7 | 7 |
|
8 | 8 | import { useData } from 'vitepress/dist/client/theme-default/composables/data' |
9 | 9 | import VPDocAsideCarbonAds from 'vitepress/dist/client/theme-default/components/VPDocAsideCarbonAds.vue' |
10 | | -const { theme } = useData() |
| 10 | +const { theme, page } = useData() |
11 | 11 |
|
12 | 12 | const { sidebarGroups, hasSidebar } = useLayout() |
13 | 13 |
|
| 14 | +// Check if current page is a blog post article |
| 15 | +const isPost = computed(() => { |
| 16 | + const path = page.value.relativePath || page.value.filePath || '' |
| 17 | + const routePath = page.value.route || '' |
| 18 | + |
| 19 | + // Post pages are in /posts/ directory, but not the list pages |
| 20 | + const isPostPath = (path.includes('/posts/') || path.startsWith('posts/')) && |
| 21 | + path.endsWith('.md') && |
| 22 | + path !== 'posts.md' && |
| 23 | + path !== 'posts/index.md' && |
| 24 | + path !== 'blog.md' && |
| 25 | + path !== 'blog/index.md' |
| 26 | + |
| 27 | + const isPostRoute = routePath.includes('/posts/') && |
| 28 | + routePath !== '/posts' && |
| 29 | + routePath !== '/posts/' && |
| 30 | + routePath !== '/blog' && |
| 31 | + routePath !== '/blog/' |
| 32 | + |
| 33 | + return isPostPath || isPostRoute |
| 34 | +}) |
| 35 | +
|
14 | 36 | const props = defineProps<{ |
15 | 37 | open: boolean |
16 | 38 | }>() |
@@ -58,7 +80,11 @@ watch( |
58 | 80 | tabindex="-1" |
59 | 81 | > |
60 | 82 |
|
61 | | - <VPDocAsideCarbonAds v-if="theme.carbonAds" :carbon-ads="theme.carbonAds" /> |
| 83 | + <!-- Show carbonAds at the top of left sidebar, only for non-post pages (API docs, etc.) --> |
| 84 | + <VPDocAsideCarbonAds |
| 85 | + v-if="!isPost && theme.carbonAds" |
| 86 | + :carbon-ads="theme.carbonAds" |
| 87 | + /> |
62 | 88 |
|
63 | 89 | <span class="visually-hidden" id="sidebar-aria-label"> |
64 | 90 | Sidebar Navigation |
|
0 commit comments