Get rid of cheerio

Not sure this one will stick, maybe my regex is too naive.
Works for common websites. Let's see
This commit is contained in:
Ronan Jouchet 2021-01-15 22:15:48 -05:00
parent 35d926b959
commit b0a953eb2d
2 changed files with 3 additions and 6 deletions

View File

@ -53,14 +53,12 @@
"watch": "npx concurrently \"npm:*:watch\""
},
"dependencies": {
"@types/cheerio": "0.x",
"@types/ncp": "2.x",
"@types/node": "10.x",
"@types/page-icon": "0.x",
"@types/shelljs": "0.x",
"@types/tmp": "0.x",
"axios": "0.x",
"cheerio": "^1.0.0-rc.3",
"commander": "4.x",
"electron-packager": "15.x",
"gitcloud": "0.x",

View File

@ -1,5 +1,4 @@
import axios from 'axios';
import * as cheerio from 'cheerio';
import * as log from 'loglevel';
const USER_AGENT =
@ -13,9 +12,9 @@ export async function inferTitle(url: string): Promise<string> {
},
});
log.debug(`Fetched ${(data.length / 1024).toFixed(1)} kb page at`, url);
const $ = cheerio.load(data);
const inferredTitle = $('title').first().text();
const inferredTitle =
/<\s*title.*?>(?<title>.+?)<\s*\/title\s*?>/i.exec(data).groups?.title ||
'Webapp';
log.debug('Inferred title:', inferredTitle);
return inferredTitle;
}