html-get 2.11.4 → 2.11.5
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/package.json +5 -3
- package/src/index.js +29 -20
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.
|
|
5
|
+
"version": "2.11.5",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"bin": {
|
|
8
8
|
"html-get": "bin/index.js"
|
|
@@ -98,7 +98,8 @@
|
|
|
98
98
|
"test/**/*.js",
|
|
99
99
|
"!test/util.js"
|
|
100
100
|
],
|
|
101
|
-
"timeout": "2m"
|
|
101
|
+
"timeout": "2m",
|
|
102
|
+
"workerThreads": false
|
|
102
103
|
},
|
|
103
104
|
"commitlint": {
|
|
104
105
|
"extends": [
|
|
@@ -107,7 +108,8 @@
|
|
|
107
108
|
},
|
|
108
109
|
"nano-staged": {
|
|
109
110
|
"*.js": [
|
|
110
|
-
"prettier-standard"
|
|
111
|
+
"prettier-standard",
|
|
112
|
+
"standard --fix"
|
|
111
113
|
],
|
|
112
114
|
"*.md": [
|
|
113
115
|
"standard-markdown"
|
package/src/index.js
CHANGED
|
@@ -152,24 +152,32 @@ const determinateMode = (url, { prerender }) => {
|
|
|
152
152
|
return isFetchMode(url) ? 'fetch' : 'prerender'
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
const getContent =
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
155
|
+
const getContent = PCancelable.fn(
|
|
156
|
+
(
|
|
157
|
+
url,
|
|
158
|
+
mode,
|
|
159
|
+
{ getBrowserless, gotOpts, headers, puppeteerOpts, rewriteUrls, toEncode },
|
|
160
|
+
onCancel
|
|
161
|
+
) => {
|
|
162
|
+
const isFetchMode = mode === 'fetch'
|
|
163
|
+
const fetchOpts = isFetchMode
|
|
164
|
+
? { headers, toEncode, ...gotOpts }
|
|
165
|
+
: { headers, toEncode, getBrowserless, gotOpts, ...puppeteerOpts }
|
|
166
|
+
|
|
167
|
+
const promise = modes[mode](url, fetchOpts)
|
|
168
|
+
onCancel(() => promise.cancel())
|
|
169
|
+
|
|
170
|
+
return promise.then(content => {
|
|
171
|
+
const html = addHtml({
|
|
172
|
+
...content,
|
|
173
|
+
...(isFetchMode ? puppeteerOpts : undefined),
|
|
174
|
+
rewriteUrls
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
return { ...content, html }
|
|
178
|
+
})
|
|
179
|
+
}
|
|
180
|
+
)
|
|
173
181
|
|
|
174
182
|
module.exports = PCancelable.fn(
|
|
175
183
|
async (
|
|
@@ -206,14 +214,15 @@ module.exports = PCancelable.fn(
|
|
|
206
214
|
toEncode
|
|
207
215
|
})
|
|
208
216
|
|
|
209
|
-
onCancel(() => promise.
|
|
217
|
+
onCancel(() => promise.cancel())
|
|
210
218
|
|
|
211
219
|
const { mode, ...payload } = await promise
|
|
212
220
|
|
|
213
|
-
return
|
|
221
|
+
return Object.assign(payload, { stats: { mode, timing: time.rounded() } })
|
|
214
222
|
}
|
|
215
223
|
)
|
|
216
224
|
|
|
217
225
|
module.exports.REQ_TIMEOUT = REQ_TIMEOUT
|
|
218
226
|
module.exports.ABORT_TYPES = ABORT_TYPES
|
|
219
227
|
module.exports.isFetchMode = isFetchMode
|
|
228
|
+
module.exports.getContent = getContent
|