File tree 9 files changed +27
-19
lines changed
9 files changed +27
-19
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ const { t } = useI18n()
20
20
const route = useRoute ()
21
21
const postTitle = route .meta .title
22
22
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/' ))
24
24
const isSharingPluginEnabled = computed (() => isPluginEnabled (' sharing' ))
25
25
const isFacebookCommentPluginEnabled = computed (() => isPluginEnabled (' facebookComment' ))
26
26
const breadcrumbItems = computed (() => {
Original file line number Diff line number Diff line change @@ -8,3 +8,10 @@ export const useQuery = () => {
8
8
9
9
return { queryParams, pushQuery }
10
10
}
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
+ }
Original file line number Diff line number Diff line change 1
1
<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'
6
3
7
4
const { t } = useI18n ()
8
5
9
6
const { searchValue, setSearchValue } = useSearch ()
10
7
11
- const router = useRouter ()
12
- const routes = router .getRoutes ().filter (route => route .path .startsWith (' /posts' ))
8
+ const routes = usePost (' /posts' )
13
9
14
10
const posts = computed (() => {
15
11
if (searchValue .value .length === 0 ) {
Original file line number Diff line number Diff line change 1
1
<script setup lang="ts">
2
+ import { usePost } from ' ~/hooks'
3
+
2
4
const { t } = useI18n ()
3
5
4
6
const { searchValue, setSearchValue } = useSearch ()
5
7
6
8
const route = useRoute ()
7
9
const slug = computed (() => route .params .slug )
8
10
9
- const router = useRouter ()
10
- const routes = router .getRoutes ().filter (route => route .path .startsWith (' /posts' ))
11
+ const routes = usePost (' /posts' )
11
12
12
13
const postFilter = (m : any ) => {
13
14
const isPost = m .type === ' post'
Original file line number Diff line number Diff line change 1
1
<script setup lang="ts">
2
+ import { usePost } from ' ~/hooks'
3
+
2
4
const { t } = useI18n ()
3
5
4
- const router = useRouter ()
5
- const routes = router .getRoutes ().filter (route => route .path .startsWith (' /posts' ))
6
+ const routes = usePost (' /posts' )
6
7
7
8
const categories = computed (() => {
8
9
const categoryCount: Record <string , number > = {}
Original file line number Diff line number Diff line change 1
1
<script setup lang="ts">
2
+ import { usePost } from ' ~/hooks'
2
3
import siteConfig from ' ~/site.config'
3
4
4
5
const { t } = useI18n ()
5
6
const siteTitle = ref (siteConfig .title )
6
7
const siteDescription = ref (siteConfig .description )
7
8
8
- const router = useRouter ()
9
- const routes = router .getRoutes ().filter (route => route .name !== undefined && route .path .startsWith (' /posts' ))
9
+ const routes = usePost (' /posts' )
10
10
11
11
const posts = computed (() => routes
12
12
.map (r => r .meta )
Original file line number Diff line number Diff line change 1
1
<script setup lang="ts">
2
+ import { usePost } from ' ~/hooks'
3
+
2
4
const { t } = useI18n ()
3
5
4
- const router = useRouter ()
5
6
const route = useRoute ()
6
- const routes = router . getRoutes (). filter ( route => route . path . startsWith ( ' /projects' ) )
7
+ const routes = usePost ( ' /projects' )
7
8
8
9
const isProjectPostType = p => p .type === ' project'
9
10
Original file line number Diff line number Diff line change 1
1
<script setup lang="ts">
2
+ import { usePost } from ' ~/hooks'
3
+
2
4
const { t } = useI18n ()
3
5
4
6
const { searchValue, setSearchValue } = useSearch ()
5
7
6
8
const route = useRoute ()
7
9
const slug = computed (() => route .params .slug )
8
10
9
- const router = useRouter ()
10
- const routes = router .getRoutes ().filter (route => route .path .startsWith (' /posts' ))
11
+ const routes = usePost (' /posts' )
11
12
12
13
const postFilter = (m : any ) => {
13
14
const isPost = m .type === ' post'
Original file line number Diff line number Diff line change 1
1
<script setup lang="ts">
2
+ import { usePost } from ' ~/hooks'
3
+
2
4
const { t } = useI18n ()
3
5
4
- const router = useRouter ()
5
- const routes = router .getRoutes ().filter (route => route .path .startsWith (' /posts' ))
6
+ const routes = usePost (' /posts' )
6
7
7
8
const tags = computed (() => {
8
9
const tagCount: Record <string , number > = {}
You can’t perform that action at this time.
0 commit comments