@@ -8,50 +8,40 @@ import classnames from 'classnames';
8
8
* WordPress dependencies
9
9
*/
10
10
const { Disabled } = wp . components ;
11
- const { Component, Fragment , RawHTML } = wp . element ;
11
+ const { Component, RawHTML } = wp . element ;
12
12
const { decodeEntities } = wp . htmlEntities ;
13
- const { __ , sprintf } = wp . i18n ;
13
+ const { __ } = wp . i18n ;
14
14
15
15
/**
16
16
* Internal dependencies
17
17
*/
18
- import { arrayToHumanReadableList } from "../shared/block-content" ;
18
+ import { tokenSplit , arrayTokenReplace , intersperse , listify } from "../shared/block-content" ;
19
19
20
20
function SessionSpeakers ( { session } ) {
21
21
let speakers ;
22
22
let speakerData = get ( session , '_embedded.speakers' , [ ] ) ;
23
23
24
- if ( speakerData . length ) {
25
- speakerData = speakerData . map ( ( speaker ) => {
26
- let { link = '' , title = { } } = speaker ;
27
- title = title . rendered || __ ( 'Unnamed' , 'wordcamporg' ) ;
24
+ speakerData = speakerData . map ( ( speaker ) => {
25
+ let { link = '' , title = { } } = speaker ;
26
+ title = title . rendered || __ ( 'Unnamed' , 'wordcamporg' ) ;
28
27
29
- return sprintf (
30
- '<a href="%s">%s</a>' ,
31
- link ,
32
- decodeEntities ( title . trim ( ) )
33
- ) ;
34
- } ) ;
28
+ if ( ! link ) {
29
+ return decodeEntities ( title . trim ( ) ) ;
30
+ }
35
31
36
- speakers = sprintf (
37
- /* translators: %s is a list of names. */
38
- __ ( 'Presented by %s' , 'wordcamporg' ) ,
39
- arrayToHumanReadableList ( speakerData )
40
- ) ;
41
- }
32
+ return ( < a href = { link } > { decodeEntities ( title . trim ( ) ) } </ a > ) ;
33
+ } ) ;
34
+
35
+ speakers = arrayTokenReplace (
36
+ /* translators: %s is a list of names. */
37
+ tokenSplit ( __ ( 'Presented by %s' , 'wordcamporg' ) ) ,
38
+ [ listify ( speakerData ) ]
39
+ ) ;
42
40
43
41
return (
44
- < Fragment >
45
- { speakers &&
46
- < div className = "wordcamp-session-speakers" >
47
- < Disabled >
48
- < RawHTML >
49
- { speakers }
50
- </ RawHTML >
51
- </ Disabled >
52
- </ div >
53
- }
54
- </ Fragment >
42
+ < div className = "wordcamp-session-speakers" >
43
+ { speakers }
44
+ </ div >
55
45
) ;
56
46
}
57
47
@@ -87,38 +77,40 @@ function SessionDetails( { session, show_meta, show_category } ) {
87
77
return 'wcb_track' === term . taxonomy ;
88
78
} ) ;
89
79
90
- metaContent = sprintf (
80
+ metaContent = arrayTokenReplace (
91
81
/* translators: 1: A date; 2: A time; 3: A location; */
92
- __ ( '%1$s at %2$s in %3$s' , 'wordcamporg' ) ,
93
- decodeEntities ( session . session_date_time . date ) ,
94
- decodeEntities ( session . session_date_time . time ) ,
95
- sprintf (
96
- '<span class="wordcamp-session-track wordcamp-session-track-%s">%s</span>' ,
97
- decodeEntities ( firstTrack . slug . trim ( ) ) ,
98
- decodeEntities ( firstTrack . name . trim ( ) )
99
- )
82
+ tokenSplit ( __ ( '%1$s at %2$s in %3$s' , 'wordcamporg' ) ) ,
83
+ [
84
+ decodeEntities ( session . session_date_time . date ) ,
85
+ decodeEntities ( session . session_date_time . time ) ,
86
+ (
87
+ < span className = { classnames ( 'wordcamp-session-track' , 'wordcamp-session-track-' + decodeEntities ( firstTrack . slug . trim ( ) ) ) } >
88
+ { decodeEntities ( firstTrack . name . trim ( ) ) }
89
+ </ span >
90
+ )
91
+ ]
100
92
) ;
101
93
} else {
102
- metaContent = sprintf (
94
+ metaContent = arrayTokenReplace (
103
95
/* translators: 1: A date; 2: A time; */
104
- __ ( '%1$s at %2$s' , 'wordcamporg' ) ,
105
- decodeEntities ( session . session_date_time . date ) ,
106
- decodeEntities ( session . session_date_time . time ) ,
96
+ tokenSplit ( __ ( '%1$s at %2$s' , 'wordcamporg' ) ) ,
97
+ [
98
+ decodeEntities ( session . session_date_time . date ) ,
99
+ decodeEntities ( session . session_date_time . time ) ,
100
+ ]
107
101
) ;
108
102
}
109
103
110
104
meta = (
111
105
< div className = "wordcamp-session-details-meta" >
112
- < RawHTML >
113
- { metaContent }
114
- </ RawHTML >
106
+ { metaContent }
115
107
</ div >
116
108
) ;
117
109
}
118
110
119
111
if ( show_category && session . session_category . length ) {
120
112
/* translators: used between list items, there is a space after the comma */
121
- const item_separator = esc_html__ ( ', ' , 'wordcamporg' ) ;
113
+ const separator = __ ( ', ' , 'wordcamporg' ) ;
122
114
const categories = terms
123
115
. filter ( ( term ) => {
124
116
return 'wcb_session_category' === term . taxonomy ;
@@ -136,20 +128,24 @@ function SessionDetails( { session, show_meta, show_category } ) {
136
128
137
129
category = (
138
130
< div className = "wordcamp-session-details-categories" >
139
- { categories . join ( item_separator ) }
131
+ { intersperse ( categories , separator ) }
140
132
</ div >
141
133
) ;
142
134
}
143
135
144
136
return (
145
137
< div className = "wordcamp-session-details" >
146
- { show_meta && meta }
147
- { show_category && category }
138
+ { meta }
139
+ { category }
148
140
</ div >
149
141
) ;
150
142
}
151
143
152
144
class SessionsBlockContent extends Component {
145
+ hasSpeaker ( session ) {
146
+ return get ( session , '_embedded.speakers' , [ ] ) . length > 0 ;
147
+ }
148
+
153
149
render ( ) {
154
150
const { attributes, sessionPosts } = this . props ;
155
151
const { className, show_speaker, show_images, image_align, image_size, content, excerpt_more, show_meta, show_category } = attributes ;
@@ -178,7 +174,7 @@ class SessionsBlockContent extends Component {
178
174
</ Disabled >
179
175
</ h3 >
180
176
181
- { show_speaker && get ( post , '_embedded.speakers' , [ ] ) . length &&
177
+ { show_speaker && this . hasSpeaker ( post ) &&
182
178
< SessionSpeakers session = { post } />
183
179
}
184
180
0 commit comments