-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
39 lines (32 loc) · 1.19 KB
/
main.ts
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
import { parseUrl, fetchArticle, processContent, verifyAbsoluteUrls } from "./src"
import { chromium } from "playwright"
import config from "./playwright.config"
async function main() {
const url = process.argv[2]
if (!url) {
console.error("Please provide a URL as an argument")
process.exit(1)
}
const browser = await chromium.launch(config.use)
const context = await browser.newContext(config.use)
const page = await context.newPage()
try {
console.log(`Fetching URL: ${url}`)
const { baseUrl, path: articlePath } = parseUrl(url)
console.log(`Base URL: ${baseUrl}, Article Path: ${articlePath}`)
const content = await fetchArticle(page, url)
console.log(`Content fetched, length: ${content.length} characters`)
const { originalPath, processedPath } = await processContent(content, baseUrl, articlePath)
console.log(`Content processed`)
verifyAbsoluteUrls(processedPath)
console.log(`Original content saved to: ${originalPath}`)
console.log(`Processed content saved to: ${processedPath}`)
} catch (error) {
console.error("An error occurred:", error)
} finally {
await browser.close()
}
}
if (require.main === module) {
main()
}