File tree Expand file tree Collapse file tree 5 files changed +41
-18
lines changed
spec/transformers/valid/ServerSideRendering
does_not_transform_amp_audio Expand file tree Collapse file tree 5 files changed +41
-18
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ const {
20
20
remove,
21
21
createElement,
22
22
insertBefore,
23
+ insertAfter,
23
24
nextNode,
24
25
firstChildByTag,
25
26
} = require ( '../NodeUtils' ) ;
@@ -81,12 +82,9 @@ class ServerSideRendering {
81
82
this . log_ . debug ( 'cannot remove boilerplate: amp-experiment' ) ;
82
83
}
83
84
84
- // amp-audio requires knowing the dimensions of the browser. Do not
85
- // remove the boilerplate or apply layout if amp-audio is present in the
86
- // document.
85
+ // Server-side rendering of an amp-audio element.
87
86
if ( node . tagName === 'amp-audio' ) {
88
- canRemoveBoilerplate = false ;
89
- this . log_ . debug ( 'cannot remove boilerplate: amp-audio' ) ;
87
+ this . ssrAmpAudio ( node ) ;
90
88
continue ;
91
89
}
92
90
@@ -211,6 +209,21 @@ class ServerSideRendering {
211
209
return nextNode ( node ) ;
212
210
}
213
211
}
212
+
213
+ ssrAmpAudio ( node ) {
214
+ // Check if we already have a SSR-ed audio element.
215
+ for ( const child of node . children || [ ] ) {
216
+ if ( child . tagName === 'audio' ) {
217
+ return ;
218
+ }
219
+ }
220
+
221
+ const audio = createElement ( 'audio' , {
222
+ controls : '' ,
223
+ } ) ;
224
+
225
+ insertAfter ( node , audio ) ;
226
+ }
214
227
}
215
228
216
229
module . exports = ServerSideRendering ;
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ < html ⚡ i-amphtml-layout i-amphtml-no-boilerplate >
2
+ < head > < style amp-runtime > </ style >
3
+ </ head >
4
+ < body >
5
+ < amp-audio > < audio controls > </ audio > </ amp-audio >
6
+ < amp-audio src ="https://example.com/audio.mp3 " width ="300 "> < audio controls > </ audio > </ amp-audio >
7
+ < amp-audio src ="https://example.com/audio.mp3 " width ="300 ">
8
+ < div fallback > Your browser doesn’t support HTML5 audio</ div >
9
+ < audio controls > </ audio >
10
+ </ amp-audio >
11
+ </ body >
12
+ </ html >
Original file line number Diff line number Diff line change
1
+ < html ⚡ >
2
+ < head > </ head >
3
+ < body >
4
+ < amp-audio > </ amp-audio >
5
+ < amp-audio src ="https://example.com/audio.mp3 " width ="300 "> </ amp-audio >
6
+ < amp-audio src ="https://example.com/audio.mp3 " width ="300 ">
7
+ < div fallback > Your browser doesn’t support HTML5 audio</ div >
8
+ < audio controls > </ audio >
9
+ </ amp-audio >
10
+ </ body >
11
+ </ html >
You can’t perform that action at this time.
0 commit comments