Explorar el Código

:sparkles: creating titles for routes

tags/0.9.0
J hace 5 años
padre
commit
27baba30cc

+ 5
- 16
vue-theme/src/pages/index.vue Ver fichero

19
                 h4.t-cap pages
19
                 h4.t-cap pages
20
                 router-link(:to="{ path: `/pages/${Object.values(allPages)[0].slug}` }")
20
                 router-link(:to="{ path: `/pages/${Object.values(allPages)[0].slug}` }")
21
                     p {{ Object.values(allPages)[0].title }}
21
                     p {{ Object.values(allPages)[0].title }}
22
+        
22
         .f-row
23
         .f-row
23
             section(v-if="allPostsLoaded").shadow
24
             section(v-if="allPostsLoaded").shadow
24
                 router-link(:to="`./posts`")
25
                 router-link(:to="`./posts`")
25
                     h4.t-cap posts
26
                     h4.t-cap posts
26
                 router-link(:to="{ path: `/posts/${Object.values(allPosts)[0].slug}` }")
27
                 router-link(:to="{ path: `/posts/${Object.values(allPosts)[0].slug}` }")
27
                     p {{ Object.values(allPosts)[0].title }}
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
         .f-row
30
         .f-row
36
             footer.f-row
31
             footer.f-row
37
                 p icon
32
                 p icon
57
             allEpisodesLoaded: 'allEpisodesLoaded',
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
         this.$store.dispatch('getAllPages')
59
         this.$store.dispatch('getAllPages')
71
         this.$store.dispatch('getAllPosts')
60
         this.$store.dispatch('getAllPosts')

+ 20
- 20
vue-theme/src/pages/list.vue Ver fichero

6
             span(v-if="sortBy")
6
             span(v-if="sortBy")
7
                 h1  sorted by {{ sortBy.replace('-', ' ') }}
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
         .posts(:class="{ 'is-grid': isGrid }")
9
         .posts(:class="{ 'is-grid': isGrid }")
15
             section(v-for="post in posts").shadow
10
             section(v-for="post in posts").shadow
16
                 router-link(:to="`/${type}/${post.slug}`")
11
                 router-link(:to="`/${type}/${post.slug}`")
17
                     h4 {{ post.title }} 
12
                     h4 {{ post.title }} 
18
                     p(style="font-size: 9px;") {{ post.date }}
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
     sidebar(v-if="sidebar" :type="`${type}`")
19
     sidebar(v-if="sidebar" :type="`${type}`")
21
         .shadow
20
         .shadow
22
             h1.t-up slots stuff
21
             h1.t-up slots stuff
61
         type() { // Checks for type and fixes Episodes route edge case 
60
         type() { // Checks for type and fixes Episodes route edge case 
62
             return typeFromRoute(this.$route)
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
         posts() {
67
         posts() {
65
             let type = convertTitleCase(this.type)
68
             let type = convertTitleCase(this.type)
66
             
69
             
75
             return this.sortBy ? this[`all${type}`] : sortedByRecent
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
             // Seperate sorting from post slugs
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
     created() {
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
 </script>
101
 </script>

+ 3
- 8
vue-theme/src/pages/single.vue Ver fichero

1
 <template lang="pug">
1
 <template lang="pug">
2
 .page--single.f-row.between
2
 .page--single.f-row.between
3
     gallery(:fullscreengallery="fullscreengallery" v-on:close="fullscreengallery = -1" :images="images")
3
     gallery(:fullscreengallery="fullscreengallery" v-on:close="fullscreengallery = -1" :images="images")
4
+    
4
     article.f-grow.shadow
5
     article.f-grow.shadow
5
         header
6
         header
6
             h1 {{ type }}:{{ $route.params.slug }} single
7
             h1 {{ type }}:{{ $route.params.slug }} single
7
         section(v-if="posts[$route.params.slug]")
8
         section(v-if="posts[$route.params.slug]")
8
             h4 {{ posts[$route.params.slug].title }}
9
             h4 {{ posts[$route.params.slug].title }}
9
             .block-wrapper(v-for="block in posts[$route.params.slug].blocks" v-html="block")
10
             .block-wrapper(v-for="block in posts[$route.params.slug].blocks" v-html="block")
11
+    
10
     sidebar(v-if="sidebar" :type="`${type}`")
12
     sidebar(v-if="sidebar" :type="`${type}`")
11
         .shadow
13
         .shadow
12
             h1.t-up single slot
14
             h1.t-up single slot
48
             allEpisodes: 'allEpisodes',
50
             allEpisodes: 'allEpisodes',
49
             allEpisodesLoaded: 'allEpisodesLoaded',
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
         type() { // Checks for type and fixes Episodes route edge case 
53
         type() { // Checks for type and fixes Episodes route edge case 
60
             return typeFromRoute(this.$route)
54
             return typeFromRoute(this.$route)
61
         },
55
         },
131
         if(!this[`all{type}Loaded`]) {
125
         if(!this[`all{type}Loaded`]) {
132
             // console.log('Retrieving...', type)
126
             // console.log('Retrieving...', type)
133
             this.$store.dispatch(`getAll${type}`)
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 Ver fichero

1
 import { createRouter, createWebHistory } from 'vue-router'
1
 import { createRouter, createWebHistory } from 'vue-router'
2
 import routes from './routes'
2
 import routes from './routes'
3
 
3
 
4
+import { convertTitleCase } from '@/utils/helpers'
5
+
4
 const router = createRouter({
6
 const router = createRouter({
5
     history: createWebHistory('/'),
7
     history: createWebHistory('/'),
6
     routes
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
 export default router
24
 export default router

+ 1
- 1
vue-theme/src/store/index.js Ver fichero

17
 
17
 
18
 // Current page state
18
 // Current page state
19
 const state = {
19
 const state = {
20
-  title: 'Test',
20
+  title: wp.site_name,
21
   hero: {
21
   hero: {
22
     url: 'http://sample-image-url/',
22
     url: 'http://sample-image-url/',
23
     text: 'sample hero text',
23
     text: 'sample hero text',

Loading…
Cancelar
Guardar