This commit is contained in:
syuilo
2016-12-11 23:12:13 +09:00
parent 4b8a5d3614
commit 927c2c19a6
3 changed files with 18 additions and 33 deletions

View File

@ -1,5 +1,4 @@
import * as URL from 'url';
import * as request from 'request';
const escapeRegExp = require('escape-regexp');
@ -33,14 +32,12 @@ export default async (url: URL.Url): Promise<ISummary> => {
$('meta[property="twitter:title"]').attr('content') ||
$('title').text();
if (title == null) {
if (title === undefined || title === null) {
return null;
}
title = clip(entities.decode(title), 100);
const lang: string = $('html').attr('lang');
let image =
$('meta[property="og:image"]').attr('content') ||
$('meta[property="twitter:image"]').attr('content') ||
@ -82,7 +79,7 @@ export default async (url: URL.Url): Promise<ISummary> => {
title = title.replace(/[\-—\|:]$/, '').trim();
}
if (title == '') {
if (title === '') {
title = siteName;
}
@ -93,17 +90,7 @@ export default async (url: URL.Url): Promise<ISummary> => {
thumbnail: image,
sitename: siteName
};
}
function promisifyRequest(request: any): (x: any) => Promise<any> {
return (x: any) => {
return new Promise<any>((resolve) => {
request(x, (a: any, b: any, c: any) => {
resolve(c);
});
});
};
}
};
function nullOrEmpty(val: string): boolean {
if (val === undefined) {

View File

@ -1,25 +1,24 @@
import * as URL from 'url';
import ISummary from '../isummary';
const client = require('cheerio-httpcli');
client.referer = false;
client.timeout = 10000;
exports.test = (url: URL.Url) =>
url.hostname == 'www.amazon.com' ||
url.hostname == 'www.amazon.co.jp' ||
url.hostname == 'www.amazon.ca' ||
url.hostname == 'www.amazon.com.br' ||
url.hostname == 'www.amazon.com.mx' ||
url.hostname == 'www.amazon.co.uk' ||
url.hostname == 'www.amazon.de' ||
url.hostname == 'www.amazon.fr' ||
url.hostname == 'www.amazon.it' ||
url.hostname == 'www.amazon.es' ||
url.hostname == 'www.amazon.nl' ||
url.hostname == 'www.amazon.cn' ||
url.hostname == 'www.amazon.in' ||
url.hostname == 'www.amazon.au'
exports.test = (url: URL.Url) =>
url.hostname === 'www.amazon.com' ||
url.hostname === 'www.amazon.co.jp' ||
url.hostname === 'www.amazon.ca' ||
url.hostname === 'www.amazon.com.br' ||
url.hostname === 'www.amazon.com.mx' ||
url.hostname === 'www.amazon.co.uk' ||
url.hostname === 'www.amazon.de' ||
url.hostname === 'www.amazon.fr' ||
url.hostname === 'www.amazon.it' ||
url.hostname === 'www.amazon.es' ||
url.hostname === 'www.amazon.nl' ||
url.hostname === 'www.amazon.cn' ||
url.hostname === 'www.amazon.in' ||
url.hostname === 'www.amazon.au'
;
exports.summary = async (url: URL.Url) => {

View File

@ -1,5 +1,4 @@
import * as URL from 'url';
import ISummary from '../isummary';
const client = require('cheerio-httpcli');
client.referer = false;