Skip to content

Commit ce25927

Browse files
authored
Feat/#9 Fetch dump markdown (#10)
* feat: add dump markdown flag * fix: undefined options * docs(changeset): _Features_ - Feat/#9 Fetch dump markdown _Chore_ - Checksum binary - fix: add extension from import (#13) - chore: not publish index.ts (#12)
1 parent 1d16674 commit ce25927

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

.changeset/shiny-peaches-thank.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
"@lightpanda/browser": minor
3+
---
4+
5+
_Features_
6+
7+
- Feat/#9 Fetch dump markdown
8+
9+
_Chore_
10+
11+
- Checksum binary
12+
- fix: add extension from import (#13)
13+
- chore: not publish index.ts (#12)

packages/browser/src/fetch.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,23 @@ import { getExecutablePath, validateUrl } from './utils.js'
2020
* @typedef LightpandaFetchOptions
2121
* @type {object}
2222
* @property {boolean} dump - Export fetched output as string
23+
* @property {boolean} dumpHtml - Export fetched output as HTML
24+
* @property {boolean} dumpMarkdown - Export fetched output as Markdown
2325
* @property {boolean} disableHostVerification - Disables host verification on all HTTP requests
2426
* @property {boolean} obeyRobots - Fetches and obeys the robots.txt (if available) of the web pages we make requests towards.
2527
* @property {string} httpProxy - The HTTP proxy to use for all HTTP requests
2628
*/
2729
export type LightpandaFetchOptions = {
28-
dump?: boolean
2930
disableHostVerification?: boolean
3031
obeyRobots?: boolean
3132
httpProxy?: string
33+
dump?: boolean
34+
dumpOptions?: { type?: 'html' | 'markdown' }
3235
}
3336

3437
const defaultOptions: LightpandaFetchOptions = {
3538
dump: true,
39+
dumpOptions: { type: 'html' },
3640
}
3741

3842
/**
@@ -42,7 +46,7 @@ const defaultOptions: LightpandaFetchOptions = {
4246
* @returns {Promise<Buffer | string>}
4347
*/
4448
export const fetch = (url: string, options: LightpandaFetchOptions = defaultOptions) => {
45-
const { dump, disableHostVerification, obeyRobots, httpProxy } = options
49+
const { dump, dumpOptions, disableHostVerification, obeyRobots, httpProxy } = options
4650
validateUrl(url)
4751

4852
if (httpProxy) {
@@ -53,7 +57,7 @@ export const fetch = (url: string, options: LightpandaFetchOptions = defaultOpti
5357
try {
5458
const executablePath = getExecutablePath()
5559
const flags = [
56-
{ flag: '--dump', condition: dump },
60+
{ flag: `--dump ${dumpOptions?.type ?? 'html'}`, condition: dump },
5761
{ flag: '--insecure_disable_tls_host_verification', condition: disableHostVerification },
5862
{ flag: '--obey_robots', condition: obeyRobots },
5963
{ flag: `--http_proxy ${httpProxy}`, condition: httpProxy },

0 commit comments

Comments
 (0)