• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ryanhefner / next-meta / 84fe578d-505e-46c8-bcab-1a67f07e02fa

09 May 2024 04:55AM UTC coverage: 9.945% (-89.5%) from 99.399%
84fe578d-505e-46c8-bcab-1a67f07e02fa

Pull #3

circleci

ryanhefner
Update CircleCI image version
Pull Request #3: v0.1.10 - Twitter Cards + Media

33 of 76 branches covered (43.42%)

Branch coverage included in aggregate %.

67 of 204 new or added lines in 2 files covered. (32.84%)

14 existing lines in 1 file now uncovered.

364 of 3916 relevant lines covered (9.3%)

1.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.02
/src/renderMeta/renderMeta.jsx
1
import React from 'react'
1✔
2

1✔
3
const getAbsoluteUrl = (url, baseUrl) => {
1✔
4
  if (baseUrl && url && url.indexOf('http') === -1) {
140✔
5
    return `${baseUrl}${url}`
3✔
6
  }
3✔
7

137✔
8
  return url
137✔
9
}
137✔
10

1✔
11
const DEFAULTS = {
1✔
12
  siteNameDelimiter: '|',
1✔
13
}
1✔
14

1✔
15
const renderMeta = (props, context) => {
1✔
16
  const {
35✔
17
    audioUrl,
35✔
18
    audioType,
35✔
19
    baseUrl,
35✔
20
    debug,
35✔
21
    description,
35✔
22
    determiner,
35✔
23
    imageUrl,
35✔
24
    imageAlt,
35✔
25
    imageWidth,
35✔
26
    imageHeight,
35✔
27
    locale,
35✔
28
    localeAlternates,
35✔
29
    siteName,
35✔
30
    siteNameDelimiter,
35✔
31
    title,
35✔
32
    twitterAppCountry,
35✔
33
    twitterAppNameGooglePlay,
35✔
34
    twitterAppIdGooglePlay,
35✔
35
    twitterAppUrlGooglePlay,
35✔
36
    twitterAppNameIPad,
35✔
37
    twitterAppIdIPad,
35✔
38
    twitterAppUrlIPad,
35✔
39
    twitterAppNameIPhone,
35✔
40
    twitterAppIdIPhone,
35✔
41
    twitterAppUrlIPhone,
35✔
42
    twitterCard,
35✔
43
    twitterCreator,
35✔
44
    twitterPlayer,
35✔
45
    twitterPlayerWidth,
35✔
46
    twitterPlayerHeight,
35✔
47
    twitterPlayerStream,
35✔
48
    twitterPlayerStreamContentType,
35✔
49
    twitterSite,
35✔
50
    type,
35✔
51
    url,
35✔
52
    videoUrl,
35✔
53
    videoType,
35✔
54
  } = { ...DEFAULTS, ...(context || {}), ...(props || {}) }
35!
55

35✔
56
  const absoluteAudioUrl = getAbsoluteUrl(audioUrl, baseUrl)
35✔
57
  const absoluteImageUrl = getAbsoluteUrl(imageUrl, baseUrl)
35✔
58
  const absoluteVideoUrl = getAbsoluteUrl(videoUrl, baseUrl)
35✔
59
  const absoluteUrl = getAbsoluteUrl(url, baseUrl)
35✔
60

35✔
61
  const tagsToRender = []
35✔
62

35✔
63
  // title
35✔
64
  if (title) {
35✔
65
    tagsToRender.push(
9✔
66
      <title key="meta-title">{`${title}${
9✔
67
        siteName ? ` ${siteNameDelimiter} ${siteName ?? siteNameContext}` : ''
9!
68
      }`}</title>,
9✔
69
      <meta key="meta-og-title" property="og:title" content={title} />,
9✔
70
      <meta key="meta-twitter-title" name="twitter:title" content={title} />,
9✔
71
    )
9✔
72
  }
9✔
73

35✔
74
  // description
35✔
75
  if (description) {
35✔
76
    tagsToRender.push(
4✔
77
      <meta key="meta-description" name="description" content={description} />,
4✔
78
      <meta
4✔
79
        key="meta-og-description"
4✔
80
        property="og:description"
4✔
81
        content={description}
4✔
82
      />,
4✔
83
      <meta
4✔
84
        key="meta-twitter-description"
4✔
85
        name="twitter:description"
4✔
86
        content={description}
4✔
87
      />,
4✔
88
    )
4✔
89
  }
4✔
90

35✔
91
  // locale
35✔
92
  if (locale) {
35✔
93
    tagsToRender.push(
1✔
94
      <meta key="meta-og-locale" property="og:locale" content={locale} />,
1✔
95
    )
1✔
96
  }
1✔
97

35✔
98
  // locale alternates
35✔
99
  if (localeAlternates && localeAlternates.length) {
35✔
100
    tagsToRender.push(
1✔
101
      localeAlternates.map((localeAlternate) => (
1✔
102
        <meta
2✔
103
          key={`meta-og-locale-alternate-${localeAlternate}`}
2✔
104
          property="og:locale:alternate"
2✔
105
          content={localeAlternate}
2✔
106
        />
2✔
107
      )),
1✔
108
    )
1✔
109
  }
1✔
110

35✔
111
  // image
35✔
112
  if (absoluteImageUrl) {
35✔
113
    tagsToRender.push(
4✔
114
      <meta
4✔
115
        key="meta-og-image"
4✔
116
        property="og:image"
4✔
117
        content={absoluteImageUrl}
4✔
118
      />,
4✔
119
      <meta
4✔
120
        key="meta-twitter-image"
4✔
121
        name="twitter:image"
4✔
122
        content={absoluteImageUrl}
4✔
123
      />,
4✔
124
    )
4✔
125

4✔
126
    // imageAlt
4✔
127
    if (imageAlt) {
4✔
128
      tagsToRender.push(
1✔
129
        <meta
1✔
130
          key="meta-og-image-alt"
1✔
131
          property="og:image:alt"
1✔
132
          content={imageAlt}
1✔
133
        />,
1✔
134
        <meta
1✔
135
          key="meta-twitter-image-alt"
1✔
136
          name="twitter:image:alt"
1✔
137
          content={imageAlt}
1✔
138
        />,
1✔
139
      )
1✔
140
    }
1✔
141

4✔
142
    // imageWidth
4✔
143
    if (imageWidth !== undefined) {
4✔
144
      tagsToRender.push(
1✔
145
        <meta
1✔
146
          key="meta-og-image-width"
1✔
147
          property="og:image:width"
1✔
148
          content={imageWidth}
1✔
149
        />,
1✔
150
      )
1✔
151
    }
1✔
152

4✔
153
    // imageHeight
4✔
154
    if (imageHeight !== undefined) {
4✔
155
      tagsToRender.push(
1✔
156
        <meta
1✔
157
          key="meta-og-image-height"
1✔
158
          property="og:image:height"
1✔
159
          content={imageHeight}
1✔
160
        />,
1✔
161
      )
1✔
162
    }
1✔
163
  }
4✔
164

35✔
165
  // determiner
35✔
166
  if (determiner) {
35✔
167
    tagsToRender.push(
1✔
168
      <meta
1✔
169
        key="meta-og-determiner"
1✔
170
        property="og:determiner"
1✔
171
        content={determiner}
1✔
172
      />,
1✔
173
    )
1✔
174
  }
1✔
175

35✔
176
  // siteName
35✔
177
  if (siteName) {
35✔
178
    tagsToRender.push(
5✔
179
      <meta
5✔
180
        key="meta-og-site-name"
5✔
181
        property="og:site_name"
5✔
182
        content={siteName}
5✔
183
      />,
5✔
184
    )
5✔
185
  }
5✔
186

35✔
187
  // twitterCard
35✔
188
  if (twitterCard) {
35✔
189
    tagsToRender.push(
1✔
190
      <meta
1✔
191
        key="meta-twitter-card"
1✔
192
        name="twitter:card"
1✔
193
        content={twitterCard}
1✔
194
      />,
1✔
195
    )
1✔
196
  }
1✔
197

35✔
198
  // Twitter Card - App
35✔
199
  // Twitter Card - App: Country
35✔
200
  if (twitterAppCountry) {
35!
NEW
201
    tagsToRender.push(
×
NEW
202
      <meta
×
NEW
203
        key="meta-twitter-app-country"
×
NEW
204
        name="twitter:app:country"
×
NEW
205
        content={twitterAppCountry}
×
NEW
206
      />,
×
NEW
207
    )
×
NEW
208
  }
×
209

35✔
210
  // Twitter Card - App: Name: Google Play
35✔
211
  if (twitterAppNameGooglePlay) {
35!
NEW
212
    tagsToRender.push(
×
NEW
213
      <meta
×
NEW
214
        key="meta-twitter-app-name-googleplay"
×
NEW
215
        name="twitter:app:name:googleplay"
×
NEW
216
        content={twitterAppNameGooglePlay}
×
NEW
217
      />,
×
NEW
218
    )
×
NEW
219
  }
×
220

35✔
221
  // Twitter Card - App: Id: Google Play
35✔
222
  if (twitterAppIdGooglePlay) {
35!
NEW
223
    tagsToRender.push(
×
NEW
224
      <meta
×
NEW
225
        key="meta-twitter-app-id-googleplay"
×
NEW
226
        name="twitter:app:id:googleplay"
×
NEW
227
        content={twitterAppIdGooglePlay}
×
NEW
228
      />,
×
NEW
229
    )
×
NEW
230
  }
×
231

35✔
232
  // Twitter Card - App: Url: Google Play
35✔
233
  if (twitterAppIdGooglePlay) {
35!
NEW
234
    tagsToRender.push(
×
NEW
235
      <meta
×
NEW
236
        key="meta-twitter-app-url-googleplay"
×
NEW
237
        name="twitter:app:url:googleplay"
×
NEW
238
        content={twitterAppUrlGooglePlay}
×
NEW
239
      />,
×
NEW
240
    )
×
NEW
241
  }
×
242

35✔
243
  // Twitter Card - App: Name: iPad
35✔
244
  if (twitterAppNameIPad) {
35!
NEW
245
    tagsToRender.push(
×
NEW
246
      <meta
×
NEW
247
        key="meta-twitter-app-name-ipad"
×
NEW
248
        name="twitter:app:name:ipad"
×
NEW
249
        content={twitterAppNameIPad}
×
NEW
250
      />,
×
NEW
251
    )
×
NEW
252
  }
×
253

35✔
254
  // Twitter Card - App: Id: iPad
35✔
255
  if (twitterAppIdIPad) {
35!
NEW
256
    tagsToRender.push(
×
NEW
257
      <meta
×
NEW
258
        key="meta-twitter-app-id-ipad"
×
NEW
259
        name="twitter:app:id:ipad"
×
NEW
260
        content={twitterAppIdIPad}
×
NEW
261
      />,
×
NEW
262
    )
×
NEW
263
  }
×
264

35✔
265
  // Twitter Card - App: Url: iPad
35✔
266
  if (twitterAppNameIPad) {
35!
NEW
267
    tagsToRender.push(
×
NEW
268
      <meta
×
NEW
269
        key="meta-twitter-app-url-ipad"
×
NEW
270
        name="twitter:app:url:ipad"
×
NEW
271
        content={twitterAppUrlIPad}
×
NEW
272
      />,
×
NEW
273
    )
×
NEW
274
  }
×
275

35✔
276
  // Twitter Card - App: Name: iPhone
35✔
277
  if (twitterAppNameIPhone) {
35!
NEW
278
    tagsToRender.push(
×
NEW
279
      <meta
×
NEW
280
        key="meta-twitter-app-name-iphone"
×
NEW
281
        name="twitter:app:name:iphone"
×
NEW
282
        content={twitterAppNameIPhone}
×
NEW
283
      />,
×
NEW
284
    )
×
NEW
285
  }
×
286

35✔
287
  // Twitter Card - App: Id: iPhone
35✔
288
  if (twitterAppIdIPhone) {
35!
NEW
289
    tagsToRender.push(
×
NEW
290
      <meta
×
NEW
291
        key="meta-twitter-app-id-iphone"
×
NEW
292
        name="twitter:app:id:iphone"
×
NEW
293
        content={twitterAppIdIPhone}
×
NEW
294
      />,
×
NEW
295
    )
×
NEW
296
  }
×
297

35✔
298
  // Twitter Card - App: Url: iPhone
35✔
299
  if (twitterAppUrlIPhone) {
35!
NEW
300
    tagsToRender.push(
×
NEW
301
      <meta
×
NEW
302
        key="meta-twitter-app-url-iphone"
×
NEW
303
        name="twitter:app:url:iphone"
×
NEW
304
        content={twitterAppUrlIPhone}
×
NEW
305
      />,
×
NEW
306
    )
×
NEW
307
  }
×
308

35✔
309
  // Twitter Card - Player
35✔
310
  if (twitterPlayer) {
35!
NEW
311
    tagsToRender.push(
×
NEW
312
      <meta
×
NEW
313
        key="meta-twitter-player"
×
NEW
314
        name="twitter:player"
×
NEW
315
        content={twitterPlayer}
×
NEW
316
      />,
×
NEW
317
    )
×
NEW
318
  }
×
319

35✔
320
  // Twitter Card - Player: Width
35✔
321
  if (twitterPlayerWidth) {
35!
NEW
322
    tagsToRender.push(
×
NEW
323
      <meta
×
NEW
324
        key="meta-twitter-player-width"
×
NEW
325
        name="twitter:player:width"
×
NEW
326
        content={twitterPlayerWidth}
×
NEW
327
      />,
×
NEW
328
    )
×
NEW
329
  }
×
330

35✔
331
  // Twitter Card - Player: Height
35✔
332
  if (twitterPlayerHeight) {
35!
NEW
333
    tagsToRender.push(
×
NEW
334
      <meta
×
NEW
335
        key="meta-twitter-player-height"
×
NEW
336
        name="twitter:player:height"
×
NEW
337
        content={twitterPlayerHeight}
×
NEW
338
      />,
×
NEW
339
    )
×
NEW
340
  }
×
341

35✔
342
  // Twitter Card - Player: Stream
35✔
343
  if (twitterPlayerStream) {
35!
NEW
344
    tagsToRender.push(
×
NEW
345
      <meta
×
NEW
346
        key="meta-twitter-player-stream"
×
NEW
347
        name="twitter:player:stream"
×
NEW
348
        content={twitterPlayerStream}
×
NEW
349
      />,
×
NEW
350
    )
×
NEW
351
  }
×
352

35✔
353
  if (twitterPlayerStreamContentType) {
35!
NEW
354
    tagsToRender.push(
×
NEW
355
      <meta
×
NEW
356
        key="meta-twitter-player-stream-content-type"
×
NEW
357
        name="twitter:player:stream:content_type"
×
NEW
358
        content={twitterPlayerStreamContentType}
×
NEW
359
      />,
×
NEW
360
    )
×
NEW
361
  }
×
362

35✔
363
  // twitterCreator
35✔
364
  if (twitterCreator) {
35✔
365
    tagsToRender.push(
1✔
366
      <meta
1✔
367
        key="meta-twitter-creator"
1✔
368
        name="twitter:creator"
1✔
369
        content={twitterCreator}
1✔
370
      />,
1✔
371
    )
1✔
372
  }
1✔
373

35✔
374
  // twitterSite
35✔
375
  if (twitterSite) {
35✔
376
    tagsToRender.push(
1✔
377
      <meta
1✔
378
        key="meta-twitter-site"
1✔
379
        name="twitter:site"
1✔
380
        content={twitterSite}
1✔
381
      />,
1✔
382
    )
1✔
383
  }
1✔
384

35✔
385
  // type
35✔
386
  if (type) {
35✔
387
    tagsToRender.push(
1✔
388
      <meta key="meta-og-type" property="og:type" content={type} />,
1✔
389
    )
1✔
390
  }
1✔
391

35✔
392
  // url
35✔
393
  if (absoluteUrl) {
35✔
394
    tagsToRender.push(
4✔
395
      <meta key="meta-og-url" property="og:url" content={absoluteUrl} />,
4✔
396
    )
4✔
397
  }
4✔
398

35✔
399
  // audio
35✔
400
  if (absoluteAudioUrl) {
35✔
401
    tagsToRender.push(
2✔
402
      <meta
2✔
403
        key="meta-og-audio"
2✔
404
        property="og:audio"
2✔
405
        content={absoluteAudioUrl}
2✔
406
      />,
2✔
407
    )
2✔
408

2✔
409
    // audio - secure_url
2✔
410
    if (absoluteAudioUrl.startsWith('https://')) {
2!
NEW
411
      tagsToRender.push(
×
NEW
412
        <meta
×
NEW
UNCOV
413
          key="meta-og-audio"
×
NEW
UNCOV
414
          property="og:audio:secure_url"
×
NEW
UNCOV
415
          content={absoluteAudioUrl}
×
NEW
UNCOV
416
        />,
×
NEW
UNCOV
417
      )
×
NEW
UNCOV
418
    }
×
419

2✔
420
    // audioType
2✔
421
    if (audioType) {
2✔
422
      tagsToRender.push(
1✔
423
        <meta
1✔
424
          key="meta-og-audio-type"
1✔
425
          property="og:audio:type"
1✔
426
          content={audioType}
1✔
427
        />,
1✔
428
      )
1✔
429
    }
1✔
430
  }
2✔
431

35✔
432
  // video
35✔
433
  if (absoluteVideoUrl) {
35✔
434
    tagsToRender.push(
2✔
435
      <meta
2✔
436
        key="meta-og-video"
2✔
437
        property="og:video"
2✔
438
        content={absoluteVideoUrl}
2✔
439
      />,
2✔
440
    )
2✔
441

2✔
442
    // video - secure_url
2✔
443
    if (absoluteVideoUrl.startsWith('https://')) {
2!
NEW
UNCOV
444
      tagsToRender.push(
×
NEW
UNCOV
445
        <meta
×
NEW
UNCOV
446
          key="meta-og-video"
×
NEW
UNCOV
447
          property="og:video:secure_url"
×
NEW
UNCOV
448
          content={absoluteVideoUrl}
×
NEW
UNCOV
449
        />,
×
NEW
UNCOV
450
      )
×
NEW
UNCOV
451
    }
×
452

2✔
453
    // videoType
2✔
454
    if (videoType) {
2✔
455
      tagsToRender.push(
1✔
456
        <meta
1✔
457
          key="meta-og-video-type"
1✔
458
          property="og:video:type"
1✔
459
          content={videoType}
1✔
460
        />,
1✔
461
      )
1✔
462
    }
1✔
463
  }
2✔
464

35✔
465
  return tagsToRender
35✔
466
}
35✔
467

1✔
468
export default renderMeta
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc