File tree 2 files changed +11
-4
lines changed
packages/metascraper-instagram 2 files changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -27,19 +27,19 @@ module.exports = () => {
27
27
const rules = {
28
28
author : ( { htmlDom : $ } ) => {
29
29
const title = $ ( 'meta[property="og:title"]' ) . attr ( 'content' )
30
- const value = title . split ( ' on Instagram' ) [ 0 ]
30
+ const value = title ? .split ( ' on Instagram' ) [ 0 ]
31
31
return author ( value )
32
32
} ,
33
33
date : ( { htmlDom : $ , url } ) => {
34
34
const description = getDescription ( url , $ )
35
- const dateMatch = description . match ( / o n ( [ ^ , ] + , \d { 4 } ) / )
36
- if ( dateMatch === null ) return
35
+ const dateMatch = description ? .match ( / o n ( [ ^ , ] + , \d { 4 } ) / )
36
+ if ( dateMatch === null || dateMatch === undefined ) return
37
37
const dateString = `${ dateMatch [ 1 ] } GMT`
38
38
return date ( new Date ( dateString ) )
39
39
} ,
40
40
lang : ( { htmlDom : $ , url } ) => {
41
41
const description = getDescription ( url , $ )
42
- const input = description . split ( ': ' ) . pop ( ) . split ( ' - ' ) . pop ( )
42
+ const input = description ? .split ( ': ' ) . pop ( ) ? .split ( ' - ' ) . pop ( )
43
43
return detectLang ( input )
44
44
} ,
45
45
title : ( { htmlDom : $ } ) =>
Original file line number Diff line number Diff line change @@ -18,6 +18,13 @@ const metascraper = require('metascraper')([
18
18
require ( 'metascraper-url' ) ( )
19
19
] )
20
20
21
+ test ( 'code is resilient' , async t => {
22
+ const url = 'https://www.instagram.com/p/CPeC-Eenc8l/'
23
+ const html = ''
24
+ const metadata = await metascraper ( { url, html } )
25
+ t . snapshot ( metadata )
26
+ } )
27
+
21
28
test ( 'from photo post' , async t => {
22
29
const url = 'https://www.instagram.com/p/CPeC-Eenc8l/'
23
30
const html = await readFile (
You can’t perform that action at this time.
0 commit comments