-
-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathcategories.vue
More file actions
90 lines (79 loc) · 2.8 KB
/
categories.vue
File metadata and controls
90 lines (79 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<script lang="ts" setup>
import { defineWebPage, useSchemaOrg } from '@unhead/schema-org/vue'
import { useCategories, useFrontmatter, useSiteStore, useValaxyI18n } from 'valaxy'
import { computed } from 'vue'
import { useI18n } from 'vue-i18n'
import { useRoute } from 'vue-router'
const { t } = useI18n()
const site = useSiteStore()
const frontmatter = useFrontmatter()
const route = useRoute()
const curCategory = computed(() => (route.query.category as string || ''))
const categories = useCategories()
const pageIcon = computed(() => {
if (!frontmatter.value.icon)
// eslint-disable-next-line vue/no-side-effects-in-computed-properties
frontmatter.value.icon = 'i-ri-folder-2-line'
return frontmatter.value.icon
})
const posts = computed(() => {
const list = site.postList.filter((post) => {
if (post.categories && curCategory.value !== 'Uncategorized') {
if (typeof post.categories === 'string')
return post.categories === curCategory.value
else
return post.categories.join('/').startsWith(curCategory.value) && post.categories[0] === curCategory.value.split('/')[0]
}
if (!post.categories && curCategory.value === 'Uncategorized')
return post.categories === undefined
return false
})
return list
})
const { $tO, $tCategory } = useValaxyI18n()
useSchemaOrg([
defineWebPage({
'@type': 'CollectionPage',
}),
])
</script>
<template>
<YunLayoutWrapper>
<YunLayoutLeft />
<RouterView v-slot="{ Component }">
<component :is="Component">
<template #main-header>
<YunPageHeader
:title="$tO(frontmatter.title) || t('menu.categories')"
:icon="pageIcon"
:color="frontmatter.color"
:page-title-class="frontmatter.pageTitleClass"
/>
</template>
<template #main-content>
<Transition
enter-active-class="animate-fade-in animate-duration-400"
appear
>
<div text="center" class="yun-text-light" p="2">
{{ t('counter.categories', Array.from(categories.children).length) }}
</div>
</Transition>
<YunCategories :categories="categories.children" />
<RouterView />
</template>
<template #main-nav-before>
<YunCard v-if="curCategory" class="post-collapse-container" m="t-4" w="full">
<YunPageHeader
m="t-10"
:title="curCategory === 'Uncategorized' ? t('category.uncategorized') : curCategory.split('/').map($tCategory).join(' / ')"
icon="i-ri-folder-open-line"
/>
<YunPostCollapse w="full" m="b-4" p="x-20 lt-sm:x-5" :posts="posts" />
</YunCard>
</template>
</component>
</RouterView>
<YunLayoutRight />
</YunLayoutWrapper>
</template>