Skip to content

Commit

Permalink
perf(theme): breadcrumb ui
Browse files Browse the repository at this point in the history
  • Loading branch information
pengzhanbo committed Aug 30, 2024
1 parent 233ae33 commit 38eb41a
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions theme/src/client/components/VPDocBreadcrumbs.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
<script setup lang="ts">
import { computed } from 'vue'
import { useRouteLocale } from 'vuepress/client'
import VPLink from '@theme/VPLink.vue'
import {
useBlogExtract,
useBlogNavTitle,
useBlogPageData,
useData,
useInternalLink,
useSidebarData,
} from '../composables/index.js'
import type { ResolvedSidebarItem } from '../../shared/index.js'
Expand All @@ -18,31 +16,28 @@ interface Breadcrumb {
}
const { page } = useData<'post'>()
const routeLocale = useRouteLocale()
const { isBlogPost } = useBlogPageData()
const { categoriesLink, blogLink } = useBlogExtract()
const { home, blog, categories } = useInternalLink()
const sidebar = useSidebarData()
const hasBreadcrumb = computed(() => {
if (isBlogPost.value && page.value.categoryList)
return page.value.categoryList.length > 0
return sidebar.value.length > 0
})
const homeTitle = useBlogNavTitle('home')
const blogTile = useBlogNavTitle('blog')
const breadcrumbList = computed<Breadcrumb[]>(() => {
if (!hasBreadcrumb.value)
return []
const list: Breadcrumb[] = [{ text: homeTitle.value, link: routeLocale.value }]
const list: Breadcrumb[] = [{ text: home.value.text, link: home.value.link }]
if (isBlogPost.value) {
list.push({ text: blogTile.value, link: blogLink.value })
list.push({ text: blog.value.text, link: blog.value.link })
const categoryList = page.value.categoryList ?? []
for (const category of categoryList) {
list.push({
text: category.name,
link: `${categoriesLink.value}?id=${category.id}`,
link: `${categories.value.link}?id=${category.id}`,
})
}
}
Expand Down Expand Up @@ -90,27 +85,27 @@ function resolveSidebar(
{{ text }}
</VPLink>
<span v-if="index !== breadcrumbList.length - 1" class="vpi-chevron-right" />
<meta property="position" :content="index + 1">
<meta property="position" :content="`${index + 1}`">
</li>
</ol>
</nav>
</template>

<style scoped>
.vp-breadcrumb {
padding-left: 1rem;
padding-left: 8px;
margin-bottom: 2rem;
border-left: solid 4px var(--vp-c-brand-1);
border-left: solid 2px var(--vp-c-brand-1);
transition: border-left var(--t-color);
}
.vp-breadcrumb ol {
display: flex;
flex-wrap: wrap;
gap: 8px;
gap: 4px;
align-items: center;
justify-content: flex-start;
font-size: 16px;
font-size: 14px;
font-weight: 400;
}
Expand All @@ -120,6 +115,7 @@ function resolveSidebar(
}
.vp-breadcrumb .breadcrumb {
font-weight: bold;
color: var(--vp-c-brand-2);
transition: color var(--t-color);
}
Expand All @@ -133,7 +129,8 @@ function resolveSidebar(
}
.vp-breadcrumb .vpi-chevron-right {
margin-left: 8px;
color: var(--vp-c-text-3);
margin-left: 4px;
color: var(--vp-c-border);
transition: color var(--t-color);
}
</style>

0 comments on commit 38eb41a

Please sign in to comment.