1
1
/* eslint-disable */
2
2
const bot = require ( '@jesses/circle-github-bot' ) . default . create ( ) ;
3
3
const Mercury = require ( '../dist/mercury.js' ) ;
4
- const fs = require ( "fs" ) ;
4
+ const fs = require ( 'fs' ) ;
5
5
6
6
const run = ( ) => {
7
7
const screenshotPath = process . argv [ 2 ] ;
@@ -11,33 +11,42 @@ const run = () => {
11
11
const html = fs . readFileSync ( `${ fixture } ` ) ;
12
12
13
13
// first parse is just to get the url
14
- Mercury . parse ( 'http://example.com' , html , { fallback : false } ) . then ( ( { url, domain, excerpt, word_count, direction } ) => {
15
- // with the url, second pass will test the correct parser
16
- Mercury . parse ( url , html , { fallback : false } ) . then ( json => {
17
- // removing excerpt b/c this comes from content, not necessary
18
- delete json . excerpt
19
-
20
- // adding items that aren't pulled in custom parser w/out fallback
21
- Object . assign ( json , { url, domain, word_count, direction } ) ;
22
-
23
- // a quick preview of the parsed content in an html file
24
- const previewHtml = `<h1>${ json . title } </h1><img src=${ json . lead_image_url } /><p>${ json . author } </p>${ json . content } `
25
-
26
-
27
- const jsonPath = `${ screenshotPath } -parsed.json` ;
28
- const fixtureArtifactPath = `tmp/artifacts/${ fixture } ` ;
29
- const previewPath = `tmp/artifacts/${ fixture } .preview.html` ;
30
-
31
- fs . writeFileSync ( previewPath , previewHtml ) ;
32
- fs . writeFileSync ( jsonPath , JSON . stringify ( json ) ) ;
33
- fs . writeFileSync ( fixtureArtifactPath , html ) ;
34
-
35
- bot . comment ( process . env . GH_AUTH_TOKEN , `### 🤖 Automated Parsing Preview 🤖
14
+ Mercury . parse ( 'http://example.com' , html , { fallback : false } ) . then (
15
+ ( { url, domain, excerpt, word_count, direction } ) => {
16
+ // with the url, second pass will test the correct parser
17
+ Mercury . parse ( url , html , { fallback : false } ) . then ( json => {
18
+ // removing excerpt b/c this comes from content, not necessary
19
+ delete json . excerpt ;
20
+
21
+ // adding items that aren't pulled in custom parser w/out fallback
22
+ Object . assign ( json , { url, domain, word_count, direction } ) ;
23
+
24
+ // a quick preview of the parsed content in an html file
25
+ const previewHtml = `<h1>${ json . title } </h1><img src=${
26
+ json . lead_image_url
27
+ } /><p>${ json . author } </p>${ json . content } `;
28
+
29
+ const jsonPath = `${ screenshotPath } -parsed.json` ;
30
+ const fixtureArtifactPath = `tmp/artifacts/${ fixture } ` ;
31
+ const previewPath = `tmp/artifacts/${ fixture } .preview.html` ;
32
+
33
+ fs . writeFileSync ( previewPath , previewHtml ) ;
34
+ fs . writeFileSync ( jsonPath , JSON . stringify ( json ) ) ;
35
+ fs . writeFileSync ( fixtureArtifactPath , html ) ;
36
+
37
+ bot . comment (
38
+ process . env . GH_AUTH_TOKEN ,
39
+ `### 🤖 Automated Parsing Preview 🤖
36
40
**Commit:** \`${ bot . env . commitMessage } \`
37
41
38
-  } )
42
+  } )
39
45
40
- [Original Article](${ url } ) | ${ bot . artifactLink ( fixtureArtifactPath , 'HTML Fixture' ) } | ${ bot . artifactLink ( previewPath , 'Parsed Content Preview' ) }
46
+ [Original Article](${ url } ) | ${ bot . artifactLink (
47
+ fixtureArtifactPath ,
48
+ 'HTML Fixture'
49
+ ) } | ${ bot . artifactLink ( previewPath , 'Parsed Content Preview' ) }
41
50
42
51
<details>
43
52
<summary><b>Parsed JSON</b></summary>
@@ -52,12 +61,15 @@ ${JSON.stringify(json, null, 2)}
52
61
53
62
**\`null\` fields**
54
63
55
- ${ Object . keys ( json ) . map ( key => json [ key ] !== null ? '' : ` * \`${ key } \n\`` ) . join ( '' ) || 'None' }
64
+ ${ Object . keys ( json )
65
+ . map ( key => ( json [ key ] !== null ? '' : ` * \`${ key } \n\`` ) )
66
+ . join ( '' ) || 'None' }
56
67
57
68
`
58
- ) ;
59
- } ) ;
60
- } ) ;
61
- }
69
+ ) ;
70
+ } ) ;
71
+ }
72
+ ) ;
73
+ } ;
62
74
63
75
run ( ) ;
0 commit comments