website-to-markdown 1.1.1 → 2.0.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/README.md +135 -5
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +3 -1
- package/dist/cli.js.map +1 -1
- package/dist/content-type.d.ts.map +1 -1
- package/dist/content-type.js +9 -8
- package/dist/content-type.js.map +1 -1
- package/dist/crawl-snapshot.d.ts +2 -1
- package/dist/crawl-snapshot.d.ts.map +1 -1
- package/dist/crawl-snapshot.js +15 -8
- package/dist/crawl-snapshot.js.map +1 -1
- package/dist/fetch-page.d.ts +38 -22
- package/dist/fetch-page.d.ts.map +1 -1
- package/dist/fetch-page.js +209 -167
- package/dist/fetch-page.js.map +1 -1
- package/dist/hash.d.ts +3 -7
- package/dist/hash.d.ts.map +1 -1
- package/dist/hash.js +3 -7
- package/dist/hash.js.map +1 -1
- package/dist/html-metadata.d.ts.map +1 -1
- package/dist/html-metadata.js +16 -20
- package/dist/html-metadata.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/limit.d.ts +1 -1
- package/dist/limit.js +1 -1
- package/dist/limit.js.map +1 -1
- package/dist/markdown-refs.d.ts +8 -0
- package/dist/markdown-refs.d.ts.map +1 -1
- package/dist/markdown-refs.js +104 -59
- package/dist/markdown-refs.js.map +1 -1
- package/dist/memory-limit.d.ts +1 -1
- package/dist/memory-limit.js +1 -1
- package/dist/memory-limit.js.map +1 -1
- package/dist/net-guard.d.ts +38 -2
- package/dist/net-guard.d.ts.map +1 -1
- package/dist/net-guard.js +88 -17
- package/dist/net-guard.js.map +1 -1
- package/dist/rate-limit-retry.d.ts.map +1 -1
- package/dist/rate-limit-retry.js +12 -21
- package/dist/rate-limit-retry.js.map +1 -1
- package/dist/read-body.d.ts +12 -0
- package/dist/read-body.d.ts.map +1 -0
- package/dist/read-body.js +40 -0
- package/dist/read-body.js.map +1 -0
- package/dist/retry-after.d.ts.map +1 -1
- package/dist/retry-after.js +8 -12
- package/dist/retry-after.js.map +1 -1
- package/dist/schema/index.d.ts +9 -0
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +28 -0
- package/dist/schema/index.js.map +1 -1
- package/dist/sitemap/index.d.ts +13 -4
- package/dist/sitemap/index.d.ts.map +1 -1
- package/dist/sitemap/index.js +58 -86
- package/dist/sitemap/index.js.map +1 -1
- package/dist/testing/index.d.ts +16 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +54 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/unchanged-page.d.ts +9 -0
- package/dist/unchanged-page.d.ts.map +1 -0
- package/dist/unchanged-page.js +31 -0
- package/dist/unchanged-page.js.map +1 -0
- package/package.json +12 -7
- package/src/cli.ts +3 -1
- package/src/content-type.ts +11 -9
- package/src/crawl-snapshot.ts +21 -8
- package/src/fetch-page.ts +304 -221
- package/src/hash.ts +3 -7
- package/src/html-metadata.ts +20 -18
- package/src/index.ts +7 -0
- package/src/limit.ts +1 -1
- package/src/markdown-refs.ts +129 -57
- package/src/memory-limit.ts +1 -1
- package/src/net-guard.ts +126 -16
- package/src/rate-limit-retry.ts +20 -20
- package/src/read-body.ts +38 -0
- package/src/retry-after.ts +11 -18
- package/src/schema/index.ts +34 -0
- package/src/sitemap/index.ts +83 -86
- package/src/testing/index.ts +60 -0
- package/src/unchanged-page.ts +37 -0
package/src/crawl-snapshot.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks'
|
|
2
2
|
import { mkdir, readFile, writeFile } from 'node:fs/promises'
|
|
3
3
|
import { resolve } from 'node:path'
|
|
4
|
+
import { invariant, type Nullable } from 'hanzio'
|
|
4
5
|
import { sha256Hex } from './hash.js'
|
|
5
6
|
import type { Logger } from './logger.js'
|
|
6
7
|
import {
|
|
@@ -40,17 +41,19 @@ export type CrawlSnapshotOptions = {
|
|
|
40
41
|
const snapshot = new AsyncLocalStorage<CrawlSnapshot>()
|
|
41
42
|
|
|
42
43
|
export function withCrawlSnapshot<T>(
|
|
43
|
-
input: CrawlSnapshotInput
|
|
44
|
+
input: Nullable<CrawlSnapshotInput>,
|
|
44
45
|
run: () => Promise<T>,
|
|
45
46
|
options: CrawlSnapshotOptions
|
|
46
47
|
) {
|
|
47
48
|
if (!input) return run()
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
invariant(
|
|
50
|
+
process.env.NODE_ENV !== 'production',
|
|
51
|
+
'A crawl snapshot is a local bench tool'
|
|
52
|
+
)
|
|
53
|
+
invariant(
|
|
54
|
+
CRAWL_SNAPSHOT_NAME_PATTERN.test(input.name),
|
|
55
|
+
`Invalid crawl snapshot name: ${input.name}`
|
|
56
|
+
)
|
|
54
57
|
|
|
55
58
|
return snapshot.run(
|
|
56
59
|
{
|
|
@@ -79,7 +82,9 @@ export async function throughCrawlSnapshot<T>(
|
|
|
79
82
|
const file = resolve(active.directory, `${sha256Hex(key).slice(0, 32)}.json`)
|
|
80
83
|
if (active.mode === 'replay') {
|
|
81
84
|
const stored = await readFile(file, 'utf8').catch(() => null)
|
|
82
|
-
|
|
85
|
+
// A file cut short by a killed recording is a miss, not a crash.
|
|
86
|
+
const parsed = stored === null ? null : parseStored<T>(stored)
|
|
87
|
+
if (parsed) return parsed.value
|
|
83
88
|
active.logger?.warn('crawl-snapshot.miss', { key })
|
|
84
89
|
}
|
|
85
90
|
|
|
@@ -89,6 +94,14 @@ export async function throughCrawlSnapshot<T>(
|
|
|
89
94
|
return value
|
|
90
95
|
}
|
|
91
96
|
|
|
97
|
+
function parseStored<T>(stored: string) {
|
|
98
|
+
try {
|
|
99
|
+
return JSON.parse(stored) as { value: T }
|
|
100
|
+
} catch {
|
|
101
|
+
return null
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
92
105
|
/** The snapshot this job reads or writes, to hand on to the job it queues. */
|
|
93
106
|
export function currentCrawlSnapshot(): CrawlSnapshotInput | null {
|
|
94
107
|
const active = snapshot.getStore()
|