File tree Expand file tree Collapse file tree 1 file changed +9
-8
lines changed
packages/metascraper-amazon Expand file tree Collapse file tree 1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -20,22 +20,23 @@ const SUFFIX_LANGUAGES = {
20
20
'it' : 'it'
21
21
}
22
22
23
- const wrap = rule => ( { htmlDom, url } ) => isAmazonUrl ( url ) && rule ( htmlDom )
24
-
25
- const wrapUrl = rule => ( { htmlDom, url } ) => {
26
- const value = wrap ( rule ) ( { htmlDom, url} )
27
- return isUrl ( value ) && value
28
- }
29
-
30
23
const getDomainLanguage = url => {
31
24
const { host} = new URL ( url )
32
25
const suffix = host . replace ( 'www.' , '' ) . split ( '.' )
33
26
suffix . shift ( )
34
27
return SUFFIX_LANGUAGES [ suffix . join ( '.' ) ]
35
28
}
36
29
30
+ const createWrap = fn => rule => ( { htmlDom, url } ) => {
31
+ const value = isAmazonUrl ( url ) && rule ( htmlDom )
32
+ return ! fn ? value : fn ( value ) && value
33
+ }
34
+
35
+ const wrap = createWrap ( )
36
+ const wrapUrl = createWrap ( value => isUrl ( value ) )
37
+
37
38
module . exports = ( ) => ( {
38
- lang : [ ( { htmlDom : $ , meta, url } ) => getDomainLanguage ( url ) ] ,
39
+ lang : [ ( { htmlDom : $ , meta, url } ) => isAmazonUrl ( url ) && getDomainLanguage ( url ) ] ,
39
40
author : [
40
41
wrap ( $ => titleize ( $ ( '.contributorNameID' ) . text ( ) ) ) ,
41
42
wrap ( $ => titleize ( $ ( '#bylineInfo' ) . text ( ) ) ) ,
You can’t perform that action at this time.
0 commit comments