ソースを参照

:recycle: adding alts in the image parser

tags/1.0.2
J 3年前
コミット
9b423efd9a

+ 7
- 0
plugins/cia-endpoints/cia-end-points.php ファイルの表示

@@ -17,6 +17,7 @@
17 17
 if ( ! defined( 'WPINC' ) ) { die; }
18 18
 
19 19
 require_once('includes/all-types.php');
20
+require_once('includes/class.make-oneofeach.php');
20 21
 require_once('includes/class.make-endpoint.php');
21 22
 require_once('includes/class.make-terms.php');
22 23
 require_once('includes/class.make-sticky.php');
@@ -53,6 +54,12 @@ add_action( 'rest_api_init', function () {
53 54
     $sticky_controller = new Make_Sticky_Endpoint();
54 55
     $sticky_controller->register_custom_route('sticky');
55 56
     
57
+    /**
58
+     * OneEach endpoint
59
+     */
60
+    $oneeach_controller = new Make_One_Each_Endpoint();
61
+    $oneeach_controller->register_custom_route('oneofeach');
62
+    
56 63
     /**
57 64
      * Terms endpoint
58 65
      */

+ 63
- 0
plugins/cia-endpoints/includes/class.make-oneofeach.php ファイルの表示

@@ -0,0 +1,63 @@
1
+<?php
2
+// include('formats.php');
3
+
4
+class Make_One_Each_Endpoint extends WP_REST_Controller {
5
+    /**
6
+     * Register the routes for the objects of the controller.
7
+     */
8
+    public function register_custom_route($route) {
9
+        $version = '2';
10
+        $namespace = 'craft/v' . $version;
11
+
12
+        register_rest_route( $namespace, '/' . $route, [
13
+            array(
14
+                'methods'  => WP_REST_Server::READABLE,
15
+                'callback' => array( $this, 'get_all_items' )
16
+            ),
17
+        ]);
18
+    }
19
+    public function get_all_items( $request ) {
20
+        $args = array(
21
+            'numberposts' => 1,
22
+        );
23
+
24
+        return new WP_REST_Response( $this->prepare_all_items_for_response($args), 200 );
25
+    }
26
+    public function prepare_all_items_for_response( $args ) {
27
+        $collection = array();
28
+        $types = [
29
+            'artist',
30
+            'episode',
31
+            'event',
32
+            'exhibition',
33
+            'guide',
34
+            'object',
35
+            'publication',
36
+            'technique',
37
+            'short',
38
+            'post',
39
+        ];
40
+
41
+        $q = [];
42
+        foreach($types as $post_type) {
43
+            array_push($q, new WP_Query(array(
44
+                'numberposts' => 1,
45
+                'post_type' => $post_type,
46
+                'post_status' => ['publish'],
47
+            )));
48
+            array_push($q, $post_type);
49
+            
50
+            $found_post = $q[0]->get_posts();
51
+
52
+            $formatted = default_post_format( $found_post, false );
53
+            $formatted['tried'] = $q[1];
54
+            array_push($collection, $formatted);
55
+        }
56
+        wp_reset_postdata();
57
+
58
+        return $collection;
59
+        // return $types;
60
+    }
61
+}
62
+
63
+?>

+ 8
- 3
plugins/cia-endpoints/includes/reformat-blocks.php ファイルの表示

@@ -3,13 +3,13 @@
3 3
         $parsed_blocks = array();
4 4
         foreach ($blocks as $block) {
5 5
             if($block[blockName] === "core/gallery") {
6
+                // Fix for new style gallery blocks
6 7
                 if(count($block[attrs][ids]) < 1) {
7 8
                     $gallery_imgs_ids = [];
8 9
                     foreach($block[innerBlocks] as $inner) {
9 10
                         $inner_id = $inner[attrs][id];
10 11
                         array_push($gallery_imgs_ids, $inner_id);
11 12
                     }
12
-                    $block[attrs]['zzz'] = $gallery_imgs_ids;
13 13
                     $block[attrs][ids] = $gallery_imgs_ids;
14 14
                 } 
15 15
                 array_push($parsed_blocks, $block[attrs]);
@@ -34,11 +34,16 @@
34 34
 
35 35
         foreach ($images as $image) {
36 36
             if($image->getAttribute('data-id')) {
37
-                $parse_images[$image->getAttribute('data-id')] = $image->getAttribute('src');
37
+                $id = $image->getAttribute('data-id');
38 38
             } else {
39 39
                 $class_pieces = explode("-", $image->getAttribute('class'));
40
-                $parse_images[end($class_pieces)] = $image->getAttribute('src');
40
+                $id = end($class_pieces);
41 41
             }
42
+            // Format for lightbox wants an object
43
+            $parse_images[$id] = [
44
+                'src' => $image->getAttribute('src'),
45
+                'title' => $image->getAttribute('alt'),
46
+            ];
42 47
         }
43 48
         return $parse_images;
44 49
     }

+ 25
- 18
vue-theme/src/pages/index.vue ファイルの表示

@@ -59,33 +59,42 @@ export default {
59 59
             // Limit the amount of posts because we
60 60
             // only need the most recent
61 61
             const params = { limit: 1 }
62
-            
62
+
63 63
             // We try and fetch EVERYTHING except
64 64
             // for EVENTS and EXHIBITIONS
65 65
             if (['event', 'exhibition'].includes(type)) {
66 66
                 // Only grab the current or upcoming on load
67
-                const eventsOrExhibitions = await this.$store.dispatch(
68
-                    action,
69
-                    { 
70
-                        sortType: sortTypes.currentAndUpcoming,
71
-                        params
72
-                    }
73
-                )
67
+                const eventsOrExhibitions = await this.$store.dispatch(action, {
68
+                    sortType: sortTypes.currentAndUpcoming,
69
+                    params,
70
+                })
74 71
                 // If no current or upcoming, get past events
75 72
                 // to fill in the blanks
76 73
                 if (eventsOrExhibitions.length < 1) {
77
-                    this.$store.dispatch(action, { sortType: sortTypes.past, params })
74
+                    this.$store.dispatch(action, {
75
+                        sortType: sortTypes.past,
76
+                        params,
77
+                    })
78 78
                 }
79
-            }
80
-            else if (!omit.includes(type)){
79
+            } else if (!omit.includes(type)) {
81 80
                 this.$store.dispatch(action, { sortType: null, params })
82 81
             }
83 82
         }
84 83
         if (!this['allPagesLoaded']) {
85
-            await this.$store.dispatch('getAllPages', { sortType: null, params: null })
84
+            await this.$store.dispatch('getAllPages', {
85
+                sortType: null,
86
+                params: null,
87
+            })
86 88
         }
87 89
         await this.checkAndSetHero('welcome')
88
-        await this.$store.dispatch('getRandomPosts', ['artist', 'guide', 'object', 'technique', 'publication', 'post'])
90
+        await this.$store.dispatch('getRandomPosts', [
91
+            'artist',
92
+            'guide',
93
+            'object',
94
+            'technique',
95
+            'publication',
96
+            'post',
97
+        ])
89 98
     },
90 99
     methods: {
91 100
         firstPostOfType(type) {
@@ -97,11 +106,9 @@ export default {
97 106
             // We always set a hero no matter what
98 107
             // Because the hero component will deal
99 108
             // with how to render based on hero.url
100
-            if(!this.allPages) return console.warn('no pages in state', this)
101
-            const page = this.allPages.filter(
102
-                page => page.slug == type,
103
-            )[0]
104
-            if(!page) return console.warn(`no page for ${type} found`)
109
+            if (!this.allPages) return console.warn('no pages in state', this)
110
+            const page = this.allPages.filter(page => page.slug == type)[0]
111
+            if (!page) return console.warn(`no page for ${type} found`)
105 112
 
106 113
             this.$store.commit('SET_HERO', this._setHeroInfo(page))
107 114
         },

+ 0
- 8
vue-theme/src/pages/single.vue ファイルの表示

@@ -202,7 +202,6 @@ export default {
202 202
             }
203 203
         },
204 204
         async singlePost(post) {
205
-            console.log('---')
206 205
             if (!this.$el) return
207 206
             const section = this.$el.children[0].querySelector('section')
208 207
             await nextTick()
@@ -215,18 +214,11 @@ export default {
215 214
                         const activeGallery =
216 215
                             post.galleries[this.activeGalleryIndex]
217 216
 
218
-                        console.log(post.galleries)
219
-                        console.log(activeGallery)
220
-
221 217
                         if (!activeGallery.ids) return
222 218
 
223 219
                         this.activeImageIndex = activeGallery.ids.indexOf(
224 220
                             parseInt(e.target.dataset.id),
225 221
                         )
226
-                        console.log(
227
-                            `opening gallery: ${this.activeGalleryIndex}.${this.activeImageIndex}`,
228
-                        )
229
-                        console.log(e.target.dataset)
230 222
                     })
231 223
                 })
232 224
             })

+ 11
- 0
vue-theme/src/utils/api.js ファイルの表示

@@ -71,6 +71,17 @@ export default {
71 71
                 cb(e)
72 72
             })
73 73
     },
74
+    async getOneOfEach(types, cb, random = false) {
75
+        let posts = []
76
+        let get = `oneofeach?types=${types.split(',')}`
77
+        if (random) {
78
+            get = get + '&orderby=rand'
79
+        }
80
+        await axios.get(SETTINGS.API_BASE_PATH + get).then(response => {
81
+            posts = [...response.data]
82
+        })
83
+        cb(posts)
84
+    },
74 85
     async getRandom(types, cb) {
75 86
         let randomPosts = []
76 87
         for (let type of types) {

読み込み中…
キャンセル
保存