Skip to content

Commit 8e80a6c

Browse files
committed
fix: duplicate post items
1 parent 239b9b1 commit 8e80a6c

File tree

9 files changed

+27
-19
lines changed

9 files changed

+27
-19
lines changed

src/components/Post.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const { t } = useI18n()
2020
const route = useRoute()
2121
const postTitle = route.meta.title
2222
const postURL = computed(() => `${baseURL}${route.path}`)
23-
const isProjectDetailPage = computed(() => route.path.startsWith('/projects/'))
23+
const isProjectDetailPage = computed(() => route.name !== undefined && route.path.startsWith('/projects/'))
2424
const isSharingPluginEnabled = computed(() => isPluginEnabled('sharing'))
2525
const isFacebookCommentPluginEnabled = computed(() => isPluginEnabled('facebookComment'))
2626
const breadcrumbItems = computed(() => {

src/hooks/route.ts

+7
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,10 @@ export const useQuery = () => {
88

99
return { queryParams, pushQuery }
1010
}
11+
12+
export const usePost = (pathPrefix: string) => {
13+
const router = useRouter()
14+
return router.getRoutes()
15+
.filter(route => route.name !== undefined
16+
&& route.path.startsWith(pathPrefix))
17+
}

src/pages/blog.vue

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
<script setup lang="ts">
2-
import { computed } from 'vue'
3-
import { useRouter } from 'vue-router'
4-
import { useI18n } from 'vue-i18n'
5-
import { useSearch } from '~/hooks'
2+
import { usePost, useSearch } from '~/hooks'
63
74
const { t } = useI18n()
85
96
const { searchValue, setSearchValue } = useSearch()
107
11-
const router = useRouter()
12-
const routes = router.getRoutes().filter(route => route.path.startsWith('/posts'))
8+
const routes = usePost('/posts')
139
1410
const posts = computed(() => {
1511
if (searchValue.value.length === 0) {

src/pages/categories/[slug].vue

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<script setup lang="ts">
2+
import { usePost } from '~/hooks'
3+
24
const { t } = useI18n()
35
46
const { searchValue, setSearchValue } = useSearch()
57
68
const route = useRoute()
79
const slug = computed(() => route.params.slug)
810
9-
const router = useRouter()
10-
const routes = router.getRoutes().filter(route => route.path.startsWith('/posts'))
11+
const routes = usePost('/posts')
1112
1213
const postFilter = (m: any) => {
1314
const isPost = m.type === 'post'

src/pages/categories/index.vue

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<script setup lang="ts">
2+
import { usePost } from '~/hooks'
3+
24
const { t } = useI18n()
35
4-
const router = useRouter()
5-
const routes = router.getRoutes().filter(route => route.path.startsWith('/posts'))
6+
const routes = usePost('/posts')
67
78
const categories = computed(() => {
89
const categoryCount: Record<string, number> = {}

src/pages/index.vue

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<script setup lang="ts">
2+
import { usePost } from '~/hooks'
23
import siteConfig from '~/site.config'
34
45
const { t } = useI18n()
56
const siteTitle = ref(siteConfig.title)
67
const siteDescription = ref(siteConfig.description)
78
8-
const router = useRouter()
9-
const routes = router.getRoutes().filter(route => route.name !== undefined && route.path.startsWith('/posts'))
9+
const routes = usePost('/posts')
1010
1111
const posts = computed(() => routes
1212
.map(r => r.meta)

src/pages/projects/index.vue

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<script setup lang="ts">
2+
import { usePost } from '~/hooks'
3+
24
const { t } = useI18n()
35
4-
const router = useRouter()
56
const route = useRoute()
6-
const routes = router.getRoutes().filter(route => route.path.startsWith('/projects'))
7+
const routes = usePost('/projects')
78
89
const isProjectPostType = p => p.type === 'project'
910

src/pages/tags/[slug].vue

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<script setup lang="ts">
2+
import { usePost } from '~/hooks'
3+
24
const { t } = useI18n()
35
46
const { searchValue, setSearchValue } = useSearch()
57
68
const route = useRoute()
79
const slug = computed(() => route.params.slug)
810
9-
const router = useRouter()
10-
const routes = router.getRoutes().filter(route => route.path.startsWith('/posts'))
11+
const routes = usePost('/posts')
1112
1213
const postFilter = (m: any) => {
1314
const isPost = m.type === 'post'

src/pages/tags/index.vue

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<script setup lang="ts">
2+
import { usePost } from '~/hooks'
3+
24
const { t } = useI18n()
35
4-
const router = useRouter()
5-
const routes = router.getRoutes().filter(route => route.path.startsWith('/posts'))
6+
const routes = usePost('/posts')
67
78
const tags = computed(() => {
89
const tagCount: Record<string, number> = {}

0 commit comments

Comments
 (0)