File tree Expand file tree Collapse file tree 13 files changed +158
-11
lines changed
metascraper-clearbit-logo/test
metascraper-logo-favicon/test
metascraper-soundcloud/test Expand file tree Collapse file tree 13 files changed +158
-11
lines changed Original file line number Diff line number Diff line change @@ -312,6 +312,15 @@ It is used for resolve relative links that can be present in the HTML markup.
312
312
313
313
it can be used as fallback field for different rules as well.
314
314
315
+ ## Environment Variables
316
+
317
+ ### METASCRAPER_CWD
318
+
319
+ Type: ` String ` <br />
320
+ Default: ` process.cwd() `
321
+
322
+ This variable is used to determine where starting search for a configuration object.
323
+
315
324
## Comparison
316
325
317
326
To give you an idea of how accurate ** metascraper** is, here is a comparison of similar libraries:
Original file line number Diff line number Diff line change @@ -15,13 +15,13 @@ let metascraper
15
15
describe ( 'metascraper-amazon' , ( ) => {
16
16
before ( ( ) => {
17
17
clearModule ( 'metascraper' )
18
- process . env . METASCRAPER_CONFIG_CWD = __dirname
18
+ process . env . METASCRAPER_CWD = __dirname
19
19
metascraper = require ( 'metascraper' )
20
20
} )
21
21
22
22
after ( ( ) => {
23
23
clearModule ( 'metascraper' )
24
- delete process . env . METASCRAPER_CONFIG_CWD
24
+ delete process . env . METASCRAPER_CWD
25
25
} )
26
26
27
27
describe ( 'amazon.co.uk' , ( ) => {
Original file line number Diff line number Diff line change @@ -6,12 +6,12 @@ const snapshot = require('snap-shot')
6
6
describe ( 'metascraper clearbit logo' , ( ) => {
7
7
before ( ( ) => {
8
8
clearModule . all ( )
9
- process . env . METASCRAPER_CONFIG_CWD = __dirname
9
+ process . env . METASCRAPER_CWD = __dirname
10
10
} )
11
11
12
12
after ( ( ) => {
13
13
clearModule . all ( )
14
- delete process . env . METASCRAPER_CONFIG_CWD
14
+ delete process . env . METASCRAPER_CWD
15
15
} )
16
16
17
17
it ( 'if logo is not present, fallback to clearbit logo API' , async ( ) => {
Original file line number Diff line number Diff line change @@ -12,12 +12,12 @@ const readFile = promisify(fs.readFile)
12
12
describe ( 'metascraper amazon integration' , ( ) => {
13
13
before ( ( ) => {
14
14
clearModule . all ( )
15
- process . env . METASCRAPER_CONFIG_CWD = __dirname
15
+ process . env . METASCRAPER_CWD = __dirname
16
16
} )
17
17
18
18
after ( ( ) => {
19
19
clearModule . all ( )
20
- delete process . env . METASCRAPER_CONFIG_CWD
20
+ delete process . env . METASCRAPER_CWD
21
21
} )
22
22
23
23
describe ( 'metascraper logo favicon' , ( ) => {
Original file line number Diff line number Diff line change @@ -13,13 +13,13 @@ let metascraper
13
13
describe ( 'metascraper-soundcloud' , ( ) => {
14
14
before ( ( ) => {
15
15
clearModule ( 'metascraper' )
16
- process . env . METASCRAPER_CONFIG_CWD = __dirname
16
+ process . env . METASCRAPER_CWD = __dirname
17
17
metascraper = require ( 'metascraper' )
18
18
} )
19
19
20
20
after ( ( ) => {
21
21
clearModule ( 'metascraper' )
22
- delete process . env . METASCRAPER_CONFIG_CWD
22
+ delete process . env . METASCRAPER_CWD
23
23
} )
24
24
25
25
it ( 'song' , async ( ) => {
Original file line number Diff line number Diff line change @@ -13,13 +13,13 @@ let metascraper
13
13
describe ( 'metascraper-youtube' , ( ) => {
14
14
before ( ( ) => {
15
15
clearModule ( 'metascraper' )
16
- process . env . METASCRAPER_CONFIG_CWD = __dirname
16
+ process . env . METASCRAPER_CWD = __dirname
17
17
metascraper = require ( 'metascraper' )
18
18
} )
19
19
20
20
after ( ( ) => {
21
21
clearModule ( 'metascraper' )
22
- delete process . env . METASCRAPER_CONFIG_CWD
22
+ delete process . env . METASCRAPER_CWD
23
23
} )
24
24
25
25
it ( 'youtube video' , async ( ) => {
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
- const cwd = process . env . METASCRAPER_CONFIG_CWD || process . cwd ( )
3
+ const cwd = process . env . METASCRAPER_CWD || process . cwd ( )
4
4
const config = require ( 'cosmiconfig' ) ( 'metascraper' ) . load ( cwd )
5
5
const resolveFrom = require ( 'resolve-from' )
6
6
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const clearModule = require ( 'clear-module' )
4
+ const should = require ( 'should' )
5
+
6
+ let metascraper
7
+
8
+ describe ( 'load rules' , ( ) => {
9
+ before ( ( ) => {
10
+ clearModule ( 'metascraper' )
11
+ process . env . METASCRAPER_CWD = __dirname
12
+ metascraper = require ( '../../../..' )
13
+ } )
14
+
15
+ after ( ( ) => {
16
+ clearModule ( 'metascraper' )
17
+ delete process . env . METASCRAPER_CWD
18
+ } )
19
+
20
+ it ( 'based on a configuration file' , async ( ) => {
21
+ const url = 'https://facebook.com'
22
+ const html = '<div></div>'
23
+
24
+ const meta = await metascraper ( { url, html } )
25
+ should ( meta . logo ) . be . equal (
26
+ 'https://logo.clearbit.com/facebook.com?size=128&format=jpg'
27
+ )
28
+ } )
29
+ } )
Original file line number Diff line number Diff line change
1
+ module . exports = {
2
+ rules : [
3
+ 'metascraper-author' ,
4
+ 'metascraper-date' ,
5
+ 'metascraper-description' ,
6
+ 'metascraper-image' ,
7
+ 'metascraper-logo' ,
8
+ {
9
+ 'metascraper-clearbit-logo' : {
10
+ format : 'jpg'
11
+ }
12
+ } ,
13
+ 'metascraper-publisher' ,
14
+ 'metascraper-title' ,
15
+ 'metascraper-url'
16
+ ]
17
+ }
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ const clearModule = require ( 'clear-module' )
4
+ const should = require ( 'should' )
5
+
6
+ let metascraper
7
+
8
+ describe ( 'load rules' , ( ) => {
9
+ before ( ( ) => {
10
+ clearModule ( 'metascraper' )
11
+ process . env . METASCRAPER_CWD = __dirname
12
+ metascraper = require ( '../../../..' )
13
+ } )
14
+
15
+ after ( ( ) => {
16
+ clearModule ( 'metascraper' )
17
+ delete process . env . METASCRAPER_CWD
18
+ } )
19
+
20
+ it ( 'based on a package file' , async ( ) => {
21
+ const url = 'https://facebook.com'
22
+ const html = '<div></div>'
23
+
24
+ const meta = await metascraper ( { url, html } )
25
+ should ( meta . logo ) . be . equal (
26
+ 'https://logo.clearbit.com/facebook.com?size=128&format=jpg'
27
+ )
28
+ } )
29
+ } )
You can’t perform that action at this time.
0 commit comments