Explorar el Código

feat: finds images on single page and puts into images prop

tags/0.9.0
John Maeda hace 6 años
padre
commit
22913132bd

+ 3
- 0
plugins/cia-endpoints/includes/class.make-endpoint.php Ver fichero

@@ -61,6 +61,9 @@ class Make_Endpoint_For extends WP_REST_Controller {
61 61
         $filtered[content] = $item->post_content;
62 62
         $filtered[blocks] = get_rearrange_blocks($item->blocks);
63 63
         
64
+        // Log the request with PHP Console
65
+        if ( class_exists( 'PC' ) ) PC::debug( $item, 'Blocks' );
66
+        
64 67
         return $filtered;
65 68
         // return $item;
66 69
     }

+ 1
- 0
plugins/cia-endpoints/includes/reformat-blocks.php Ver fichero

@@ -1,6 +1,7 @@
1 1
 <?php
2 2
     function get_rearrange_blocks($blocks) {
3 3
         $parsed_blocks = array();
4
+
4 5
         foreach( $blocks as $block ) {
5 6
             if(sizeof($block[innerBlocks]) < 1 && $block[innerHTML] !== "\n\n") {
6 7
                 array_push($parsed_blocks, $block[innerHTML]);

+ 0
- 1
plugins/cia-post-types/cia-post-types.php Ver fichero

@@ -65,4 +65,3 @@ foreach ($custom_types as $type):
65 65
     $icon = get_icon($type);
66 66
     add_action( 'init', [ new PostType($type, $icon), 'register_post_type' ] );
67 67
 endforeach;
68
-

+ 32
- 9
vue-theme/src/components/gallery.vue Ver fichero

@@ -2,21 +2,33 @@
2 2
 .gallery.f-col.center(v-if="fullscreengallery")
3 3
     button(@click="hideGallery") hide
4 4
     ul
5
-        li
6
-            h1 hello world
7
-        li
8
-            h1 hello world again
5
+        li(v-for="(image, i) of images" :class="{ active: i === selected }")
6
+            .image-wrapper.f-row.center
7
+                img(:src="image")
9 8
     .controls.f-row
10
-        button(@click="hideGallery") <<<
11
-        button(@click="hideGallery") >>>
9
+        button(@click="prev") <
10
+        .f-grow
11
+        button(@click="next") >
12 12
 </template>
13 13
 
14 14
 <script>
15 15
 export default {
16 16
     props: {
17
+        images: { type: Array },
17 18
         fullscreengallery: { type: Boolean }
18 19
     },
20
+    data() { 
21
+        return {
22
+            selected: 0
23
+        }
24
+    },
19 25
     methods: {
26
+        prev() {
27
+            this.selected > 0 ? this.selected-- : this.selected = this.images.length - 1
28
+        },
29
+        next() {
30
+            this.selected < this.images.length - 1 ? this.selected++ : this.selected = 0
31
+        },
20 32
         hideGallery() {
21 33
             this.$emit('close')
22 34
         }
@@ -30,7 +42,7 @@ export default {
30 42
     top: 0
31 43
     left: 0
32 44
     width: 100%
33
-    height: 100vw
45
+    height: 100%
34 46
     background-color: blue
35 47
     opacity: 75%
36 48
     z-index: 1001
@@ -40,6 +52,17 @@ export default {
40 52
         z-index: 1011
41 53
     ul
42 54
         list-style: none
43
-        h1
44
-            color: green
55
+        li
56
+            display: none
57
+            &.active
58
+                display: block
59
+            .image-wrapper
60
+                height: 100%
61
+                width: 50vw
62
+                background-color: yellow
63
+            h1
64
+                color: green
65
+    .controls
66
+        position: absolute
67
+        bottom: 5em
45 68
 </style>

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

@@ -1,11 +1,11 @@
1 1
 <template lang="pug">
2
-.page--single.f-row.between
3
-    gallery(:fullscreengallery="fullscreengallery" v-on:close="fullscreengallery = false")
2
+.page--single.f-row.between(v-if="$route.params.slug")
3
+    gallery(v-if="images.length" :fullscreengallery="fullscreengallery" v-on:close="fullscreengallery = false" :images="images")
4 4
     article.f-grow.shadow
5 5
         header
6 6
             h1 {{ type }}:{{ $route.params.slug }} single
7 7
             button(@click="fullscreengallery = true") fullscreen
8
-        section
8
+        section(v-if="posts[$route.params.slug]")
9 9
             h4 {{ posts[$route.params.slug].title }}
10 10
             .block-wrapper(v-for="block in posts[$route.params.slug].blocks" v-html="block")
11 11
     sidebar(v-if="sidebar" :type="`${type}`")
@@ -32,6 +32,7 @@ export default {
32 32
     },
33 33
     data() {
34 34
         return {
35
+            images: [], 
35 36
             fullscreengallery: false
36 37
         }
37 38
     },
@@ -62,11 +63,36 @@ export default {
62 63
             }, {})
63 64
         },
64 65
     },
66
+    methods: {
67
+        checkForImages(post) {
68
+            const allBlocks = post[this.$route.params.slug].blocks.map(block => {
69
+                if(block) return block
70
+            })
71
+            allBlocks.forEach(block => {
72
+                if(!block) return
73
+
74
+                const domparser = new DOMParser()
75
+                const doc = domparser.parseFromString(block, 'text/html')
76
+
77
+                const gallery = doc.querySelectorAll('.blocks-gallery-item img')
78
+                if(gallery) {
79
+                    this.images = [].slice.call(gallery).map(item => { return item.src })
80
+                }
81
+            })
82
+        }
83
+    },
84
+    watch: {
85
+        posts(newVal, oldVal) {
86
+            this.checkForImages(newVal)
87
+        }
88
+    },
65 89
     mounted() {
66 90
         // TODO: this should be conditional after checking vuex state
67 91
         let type = this.$route.params.type
68 92
         type = type.charAt(0).toUpperCase() + type.slice(1)
69 93
         this.$store.dispatch(`getAll${type}`)
94
+        
95
+        console.log(this.images)
70 96
     }
71 97
 }
72 98
 </script>

Loading…
Cancelar
Guardar