浏览代码

:sparkles: creating titles for routes

tags/0.9.0
J 5 年前
父节点
当前提交
27baba30cc

+ 5
- 16
vue-theme/src/pages/index.vue 查看文件

@@ -19,19 +19,14 @@
19 19
                 h4.t-cap pages
20 20
                 router-link(:to="{ path: `/pages/${Object.values(allPages)[0].slug}` }")
21 21
                     p {{ Object.values(allPages)[0].title }}
22
+        
22 23
         .f-row
23 24
             section(v-if="allPostsLoaded").shadow
24 25
                 router-link(:to="`./posts`")
25 26
                     h4.t-cap posts
26 27
                 router-link(:to="{ path: `/posts/${Object.values(allPosts)[0].slug}` }")
27 28
                     p {{ Object.values(allPosts)[0].title }}
28
-        .f-row
29
-            section
30
-                //- COMPONENT: Looping component
31
-                .post(v-for="post in allPosts")
32
-                    h4.post--title {{ post.slug }}
33
-                    ul.post--content
34
-                        li.post--content--block(v-for="block in post.blocks" v-html="block")
29
+     
35 30
         .f-row
36 31
             footer.f-row
37 32
                 p icon
@@ -57,15 +52,9 @@ export default {
57 52
             allEpisodesLoaded: 'allEpisodesLoaded',
58 53
         }),
59 54
     },
60
-    data() {
61
-        return {
62
-            site: wp.site_name,
63
-        }
64
-    },
65
-    mounted() {
66
-        console.log('routes: ', wp.routes)
67
-        console.log('rest url: ', wp.rest)
68
-        console.log('template: ', wp.template)
55
+    created() {
56
+        console.log(wp)
57
+        console.log(this.$store.state.title)
69 58
 
70 59
         this.$store.dispatch('getAllPages')
71 60
         this.$store.dispatch('getAllPosts')

+ 20
- 20
vue-theme/src/pages/list.vue 查看文件

@@ -6,17 +6,16 @@
6 6
             span(v-if="sortBy")
7 7
                 h1  sorted by {{ sortBy.replace('-', ' ') }}
8 8
 
9
-        section.shadow
10
-            h4 {{ type }}
11
-            p {{ Object.values(posts).length }}
12
-            p {{ sidebar }}
13
-        
14 9
         .posts(:class="{ 'is-grid': isGrid }")
15 10
             section(v-for="post in posts").shadow
16 11
                 router-link(:to="`/${type}/${post.slug}`")
17 12
                     h4 {{ post.title }} 
18 13
                     p(style="font-size: 9px;") {{ post.date }}
19 14
 
15
+        footer
16
+            p {{ `${type} count: ${Object.values(posts).length}` }}
17
+            p {{ `show sidebar: ${sidebar}` }}
18
+        
20 19
     sidebar(v-if="sidebar" :type="`${type}`")
21 20
         .shadow
22 21
             h1.t-up slots stuff
@@ -61,6 +60,10 @@ export default {
61 60
         type() { // Checks for type and fixes Episodes route edge case 
62 61
             return typeFromRoute(this.$route)
63 62
         },
63
+        dispatchName() {
64
+            let type = convertTitleCase(this.type)
65
+            return this.sortBy ? `getAll${type.split('/')[0]}` : `getAll${type}`
66
+        },
64 67
         posts() {
65 68
             let type = convertTitleCase(this.type)
66 69
             
@@ -75,27 +78,24 @@ export default {
75 78
             return this.sortBy ? this[`all${type}`] : sortedByRecent
76 79
         },
77 80
     },
78
-    watch: {
79
-        $route(to, from){
80
-            let type = convertTitleCase(to.path.slice(1))
81
+    methods: {
82
+        setHeroAndGetPosts() {
83
+            let type = convertTitleCase(this.type)
81 84
 
82
-            // Accounts for the sort-by in URL case 
83
-            let dispatchName = this.sortBy ? `getAll${type.split('/')[0]}` : `getAll${type}`
84
-            
85 85
             // Seperate sorting from post slugs
86
-            if(Object.values(sortTypes).indexOf(this.sortBy) >= 0) {
87
-                this.$store.dispatch(dispatchName, this.sortBy)
88
-            }
89
-            if(this.$store.state.hero.url !== type) {
90
-                this.$store.commit('SET_HERO', type)
86
+            if(!this.sortBy || Object.values(sortTypes).indexOf(this.sortBy) >= 0) { 
87
+                this.$store.dispatch(this.dispatchName, this.sortBy)
91 88
             }
89
+            if(this.$store.state.hero.url !== type) this.$store.commit('SET_HERO', type)
90
+        }
91
+    },
92
+    watch: {
93
+        $route(to, from){
94
+            this.setHeroAndGetPosts()
92 95
         }
93 96
     },
94 97
     created() {
95
-        let type = convertTitleCase(this.type)
96
-        
97
-        this.$store.dispatch(`getAll${type}`, this.sortBy)
98
-        this.$store.commit('SET_HERO', type)
98
+        this.setHeroAndGetPosts()
99 99
     }
100 100
 }
101 101
 </script>

+ 3
- 8
vue-theme/src/pages/single.vue 查看文件

@@ -1,12 +1,14 @@
1 1
 <template lang="pug">
2 2
 .page--single.f-row.between
3 3
     gallery(:fullscreengallery="fullscreengallery" v-on:close="fullscreengallery = -1" :images="images")
4
+    
4 5
     article.f-grow.shadow
5 6
         header
6 7
             h1 {{ type }}:{{ $route.params.slug }} single
7 8
         section(v-if="posts[$route.params.slug]")
8 9
             h4 {{ posts[$route.params.slug].title }}
9 10
             .block-wrapper(v-for="block in posts[$route.params.slug].blocks" v-html="block")
11
+    
10 12
     sidebar(v-if="sidebar" :type="`${type}`")
11 13
         .shadow
12 14
             h1.t-up single slot
@@ -48,14 +50,6 @@ export default {
48 50
             allEpisodes: 'allEpisodes',
49 51
             allEpisodesLoaded: 'allEpisodesLoaded',
50 52
         }),
51
-        allLoaded() {
52
-            const flags = []
53
-            flags.push(this.allPagesLoaded)
54
-            flags.push(this.allPostsLoaded)
55
-            flags.push(this.allArtistsLoaded)
56
-            flags.push(this.allEpisodesLoaded)
57
-            return flags.every(Boolean)
58
-        },
59 53
         type() { // Checks for type and fixes Episodes route edge case 
60 54
             return typeFromRoute(this.$route)
61 55
         },
@@ -131,6 +125,7 @@ export default {
131 125
         if(!this[`all{type}Loaded`]) {
132 126
             // console.log('Retrieving...', type)
133 127
             this.$store.dispatch(`getAll${type}`)
128
+            // posts watcher will fire after this
134 129
         }
135 130
     }
136 131
 }

+ 15
- 0
vue-theme/src/router/index.js 查看文件

@@ -1,9 +1,24 @@
1 1
 import { createRouter, createWebHistory } from 'vue-router'
2 2
 import routes from './routes'
3 3
 
4
+import { convertTitleCase } from '@/utils/helpers'
5
+
4 6
 const router = createRouter({
5 7
     history: createWebHistory('/'),
6 8
     routes
7 9
 })
8 10
 
11
+router.beforeEach((to, from, next) => {
12
+    document.title = 'Craft in America'
13
+    // Append list type
14
+    if(to.path.split('/').length > 1 && to.path.split('/')[1]) {
15
+        const path = convertTitleCase(to.path.split('/')[1])
16
+        document.title = `${document.title} - ${path}`
17
+    }
18
+    // Append slugs and sort titles
19
+    if(to.path.split('/')[2]) document.title = `${document.title} - ${to.path.split('/')[2]}`
20
+
21
+    next()
22
+})
23
+
9 24
 export default router

+ 1
- 1
vue-theme/src/store/index.js 查看文件

@@ -17,7 +17,7 @@ const debug = process.env.NODE_ENV !== 'production'
17 17
 
18 18
 // Current page state
19 19
 const state = {
20
-  title: 'Test',
20
+  title: wp.site_name,
21 21
   hero: {
22 22
     url: 'http://sample-image-url/',
23 23
     text: 'sample hero text',

正在加载...
取消
保存