2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-06-11 16:42:21 +00:00
nativefier/src/infer/inferTitle.js
Jia Hao Goh 8f78dd03af Update eslint and use Airbnb style
- Add `npm run lint:fix` command
- Cleanup inferIcon.js logic slightly
2017-04-29 22:52:12 +08:00

23 lines
597 B
JavaScript

import axios from 'axios';
import cheerio from 'cheerio';
const USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36';
function inferTitle(url) {
const options = {
method: 'get',
url,
headers: {
// fake a user agent because pages like http://messenger.com will throw 404 error
'User-Agent': USER_AGENT,
},
};
return axios(options).then(({ data }) => {
const $ = cheerio.load(data);
return $('title').first().text().replace(/\//g, '');
});
}
export default inferTitle;