-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarkdownify.ts
More file actions
40 lines (35 loc) · 1.22 KB
/
markdownify.ts
File metadata and controls
40 lines (35 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { defineCommand } from "citty";
import { resolveApiKey } from "../lib/folders.js";
import * as log from "../lib/log.js";
import * as scrapegraphai from "../lib/scrapegraphai.js";
export default defineCommand({
meta: {
name: "markdownify",
description: "Convert a webpage to clean markdown",
},
args: {
url: {
type: "positional",
description: "Website URL to convert",
required: true,
},
stealth: { type: "boolean", description: "Bypass bot detection (+4 credits)" },
headers: { type: "string", description: "Custom headers as JSON object string" },
json: { type: "boolean", description: "Output raw JSON (pipeable)" },
},
run: async ({ args }) => {
const out = log.create(!!args.json);
out.docs("https://docs.scrapegraphai.com/services/markdownify");
const key = await resolveApiKey(!!args.json);
const params: scrapegraphai.MarkdownifyParams = {
website_url: args.url,
};
if (args.stealth) params.stealth = true;
if (args.headers) params.headers = JSON.parse(args.headers);
out.start("Converting to markdown");
const result = await scrapegraphai.markdownify(key, params);
out.stop(result.elapsedMs);
if (result.data) out.result(result.data);
else out.error(result.error);
},
});