html-get 2.27.16 → 2.27.17
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 +1 -1
- package/src/html.js +1 -1
- package/src/index.js +10 -0
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "html-get",
|
|
3
3
|
"description": "Get the HTML from any website, fine-tuned for correction & speed",
|
|
4
4
|
"homepage": "https://nicedoc.com/microlinkhq/html-get",
|
|
5
|
-
"version": "2.27.
|
|
5
|
+
"version": "2.27.17",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"main": "src/index.js",
|
|
8
8
|
"bin": {
|
package/src/html.js
CHANGED
|
@@ -30,7 +30,7 @@ const addHead = ({ $, url, headers, pdfMeta = {} }) => {
|
|
|
30
30
|
const charset = getCharset(headers)
|
|
31
31
|
const { domain } = parseUrl(url)
|
|
32
32
|
const head = $('head')
|
|
33
|
-
const title = pdfMeta.title || path.basename(url)
|
|
33
|
+
const title = pdfMeta.title || path.basename(url.split('#')[0])
|
|
34
34
|
const siteName = pdfMeta.publisher || domain
|
|
35
35
|
|
|
36
36
|
upsert(head.find('title'), tags, `<title>${escapeAttr(title)}</title>`)
|
package/src/index.js
CHANGED
|
@@ -26,6 +26,12 @@ const ABORT_TYPES = ['image', 'stylesheet', 'font']
|
|
|
26
26
|
|
|
27
27
|
const PDF_SIZE_TRESHOLD = 150 * 1024 // 150kb
|
|
28
28
|
|
|
29
|
+
// `URL#hash` is empty both when the fragment is missing and when it is
|
|
30
|
+
// empty. An empty fragment is still present on `href`, and it must win.
|
|
31
|
+
const inheritRequestFragment = (options, response) => {
|
|
32
|
+
if (!options.url.href.includes('#')) options.url.hash = new URL(response.url).hash
|
|
33
|
+
}
|
|
34
|
+
|
|
29
35
|
const fetch = PCancelable.fn(
|
|
30
36
|
async (
|
|
31
37
|
url,
|
|
@@ -36,6 +42,10 @@ const fetch = PCancelable.fn(
|
|
|
36
42
|
|
|
37
43
|
const req = got(url, {
|
|
38
44
|
...opts,
|
|
45
|
+
hooks: {
|
|
46
|
+
...opts.hooks,
|
|
47
|
+
beforeRedirect: [inheritRequestFragment].concat(opts.hooks?.beforeRedirect || [])
|
|
48
|
+
},
|
|
39
49
|
timeout: reqTimeout,
|
|
40
50
|
responseType: 'buffer'
|
|
41
51
|
})
|