html-get 2.11.6 → 2.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/index.js CHANGED
@@ -3,8 +3,8 @@
3
3
  'use strict'
4
4
 
5
5
  const createBrowserless = require('browserless')
6
- const mri = require('mri')
7
6
  const { URL } = require('url')
7
+ const mri = require('mri')
8
8
 
9
9
  const getHTML = require('..')
10
10
 
@@ -26,9 +26,9 @@ getHTML(url, { getBrowserless, ...args })
26
26
  headers: ${
27
27
  headers
28
28
  ? Object.keys(headers).reduce(
29
- (acc, key) => `${acc}${key}=${headers[key]} `,
30
- ''
31
- )
29
+ (acc, key) => `${acc}${key}=${headers[key]} `,
30
+ ''
31
+ )
32
32
  : '-'
33
33
  }
34
34
  `)
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "html-get",
3
3
  "description": "Get the HTML from any website, using prerendering when is necessary.",
4
4
  "homepage": "https://nicedoc.com/microlinkhq/html-get",
5
- "version": "2.11.6",
5
+ "version": "2.13.0",
6
6
  "main": "src/index.js",
7
7
  "bin": {
8
8
  "html-get": "bin/index.js"
@@ -2,37 +2,37 @@
2
2
  [
3
3
  [
4
4
  "domainWithoutSuffix",
5
- "youtube"
5
+ "google"
6
6
  ]
7
7
  ],
8
8
  [
9
9
  [
10
10
  "domainWithoutSuffix",
11
- "google"
11
+ "youtube"
12
12
  ]
13
13
  ],
14
14
  [
15
15
  [
16
16
  "domainWithoutSuffix",
17
- "wordpress"
17
+ "apple"
18
18
  ]
19
19
  ],
20
20
  [
21
21
  [
22
22
  "domainWithoutSuffix",
23
- "apple"
23
+ "wordpress"
24
24
  ]
25
25
  ],
26
26
  [
27
27
  [
28
28
  "domainWithoutSuffix",
29
- "wikipedia"
29
+ "microsoft"
30
30
  ]
31
31
  ],
32
32
  [
33
33
  [
34
34
  "domainWithoutSuffix",
35
- "microsoft"
35
+ "wikipedia"
36
36
  ]
37
37
  ],
38
38
  [
@@ -56,7 +56,7 @@
56
56
  [
57
57
  [
58
58
  "domainWithoutSuffix",
59
- "nytimes"
59
+ "slideshare"
60
60
  ]
61
61
  ],
62
62
  [
@@ -68,7 +68,7 @@
68
68
  [
69
69
  [
70
70
  "domainWithoutSuffix",
71
- "theguardian"
71
+ "nytimes"
72
72
  ]
73
73
  ],
74
74
  [
@@ -80,31 +80,31 @@
80
80
  [
81
81
  [
82
82
  "domainWithoutSuffix",
83
- "slideshare"
83
+ "theguardian"
84
84
  ]
85
85
  ],
86
86
  [
87
87
  [
88
88
  "domainWithoutSuffix",
89
- "soundcloud"
89
+ "telegraph"
90
90
  ]
91
91
  ],
92
92
  [
93
93
  [
94
94
  "domainWithoutSuffix",
95
- "huffingtonpost"
95
+ "pinterest"
96
96
  ]
97
97
  ],
98
98
  [
99
99
  [
100
100
  "domainWithoutSuffix",
101
- "pinterest"
101
+ "huffingtonpost"
102
102
  ]
103
103
  ],
104
104
  [
105
105
  [
106
106
  "domainWithoutSuffix",
107
- "telegraph"
107
+ "soundcloud"
108
108
  ]
109
109
  ],
110
110
  [
@@ -116,55 +116,61 @@
116
116
  [
117
117
  [
118
118
  "domainWithoutSuffix",
119
- "techcrunch"
119
+ "eventbrite"
120
120
  ]
121
121
  ],
122
122
  [
123
123
  [
124
124
  "domainWithoutSuffix",
125
- "zoom"
125
+ "yelp"
126
126
  ]
127
127
  ],
128
128
  [
129
129
  [
130
130
  "domainWithoutSuffix",
131
- "yelp"
131
+ "engadget"
132
132
  ]
133
133
  ],
134
134
  [
135
135
  [
136
- "domain",
137
- "abc.net.au"
136
+ "domainWithoutSuffix",
137
+ "techcrunch"
138
138
  ]
139
139
  ],
140
140
  [
141
141
  [
142
142
  "domainWithoutSuffix",
143
- "eventbrite"
143
+ "zoom"
144
144
  ]
145
145
  ],
146
146
  [
147
147
  [
148
148
  "domainWithoutSuffix",
149
- "engadget"
149
+ "theverge"
150
+ ]
151
+ ],
152
+ [
153
+ [
154
+ "domain",
155
+ "abc.net.au"
150
156
  ]
151
157
  ],
152
158
  [
153
159
  [
154
160
  "domainWithoutSuffix",
155
- "theverge"
161
+ "etsy"
156
162
  ]
157
163
  ],
158
164
  [
159
165
  [
160
166
  "domainWithoutSuffix",
161
- "giphy"
167
+ "stackoverflow"
162
168
  ]
163
169
  ],
164
170
  [
165
171
  [
166
172
  "domainWithoutSuffix",
167
- "dribbble"
173
+ "flickr"
168
174
  ]
169
175
  ],
170
176
  [
@@ -188,19 +194,19 @@
188
194
  [
189
195
  [
190
196
  "domainWithoutSuffix",
191
- "etsy"
197
+ "dribbble"
192
198
  ]
193
199
  ],
194
200
  [
195
201
  [
196
202
  "domainWithoutSuffix",
197
- "flickr"
203
+ "ghost"
198
204
  ]
199
205
  ],
200
206
  [
201
207
  [
202
208
  "domainWithoutSuffix",
203
- "ghost"
209
+ "giphy"
204
210
  ]
205
211
  ],
206
212
  [
@@ -233,12 +239,6 @@
233
239
  "sourceforge"
234
240
  ]
235
241
  ],
236
- [
237
- [
238
- "domainWithoutSuffix",
239
- "stackoverflow"
240
- ]
241
- ],
242
242
  [
243
243
  [
244
244
  "domainWithoutSuffix",
package/src/html.js CHANGED
@@ -22,12 +22,21 @@ const has = el => el.length !== 0
22
22
 
23
23
  const upsert = (el, collection, item) => !has(el) && collection.push(item)
24
24
 
25
+ /**
26
+ * Infer timestamp from `last-modified`, `date`, or `age` response headers.
27
+ */
28
+ const getDate = headers => {
29
+ const timestamp = get(headers, 'last-modified') || get(headers, 'date')
30
+ return timestamp
31
+ ? toDate(timestamp)
32
+ : toDate(Date.now() - Number(get(headers, 'age')) * 1000)
33
+ }
34
+
25
35
  const addHead = ({ $, url, headers }) => {
26
36
  const tags = []
27
37
  const contentType = get(headers, 'content-type')
28
38
  const charset = nth(split(contentType, 'charset='), 1)
29
- const timestamp = get(headers, 'last-modified') || get(headers, 'date')
30
- const date = timestamp && toDate(timestamp)
39
+ const date = getDate(headers)
31
40
  const { domain } = parseUrl(url)
32
41
  const head = $('head')
33
42
 
@@ -70,9 +79,9 @@ const addBody = ({ url, headers, html }) => {
70
79
  if (isMime(contentType, 'image')) {
71
80
  element = `<img src="${url}"></img>`
72
81
  } else if (isMime(contentType, 'video')) {
73
- element = `<video src="${url}"></video>`
82
+ element = `<video><source src="${url}" type="${contentType}"></source></video>`
74
83
  } else if (isMime(contentType, 'audio')) {
75
- element = `<audio src="${url}"></audio>`
84
+ element = `<audio><source src="${url}" type="${contentType}"></source></audio>`
76
85
  } else if (mimeExtension(contentType) === 'json') {
77
86
  element = `<pre>${html}</pre>`
78
87
  }
@@ -179,3 +188,5 @@ module.exports = ({
179
188
 
180
189
  return rewriteUrls ? rewriteCssUrls({ html: $.html(), url }) : $.html()
181
190
  }
191
+
192
+ module.exports.getDate = getDate