Merge pull request #8 from armchair-philosophy/escape-commonJS

escape from commonJS concept
This commit is contained in:
syuilo⭐️ 2017-01-30 12:06:19 +09:00 committed by GitHub
commit af20d95845
3 changed files with 33 additions and 26 deletions

View File

@ -4,9 +4,13 @@ import ISummary from './isummary';
import IPlugin from './iplugin'; import IPlugin from './iplugin';
import general from './general'; import general from './general';
/* plugins */
import * as amazon from './plugins/amazon';
import * as wikipedia from './plugins/wikipedia';
const plugins: IPlugin[] = [ const plugins: IPlugin[] = [
require('./plugins/amazon'), amazon,
require('./plugins/wikipedia') wikipedia
]; ];
export default async (url: string): Promise<ISummary> => { export default async (url: string): Promise<ISummary> => {

View File

@ -4,8 +4,8 @@ const client = require('cheerio-httpcli');
client.referer = false; client.referer = false;
client.timeout = 10000; client.timeout = 10000;
exports.test = (url: URL.Url) => export function test (url: URL.Url) {
url.hostname === 'www.amazon.com' || return url.hostname === 'www.amazon.com' ||
url.hostname === 'www.amazon.co.jp' || url.hostname === 'www.amazon.co.jp' ||
url.hostname === 'www.amazon.ca' || url.hostname === 'www.amazon.ca' ||
url.hostname === 'www.amazon.com.br' || url.hostname === 'www.amazon.com.br' ||
@ -19,9 +19,9 @@ exports.test = (url: URL.Url) =>
url.hostname === 'www.amazon.cn' || url.hostname === 'www.amazon.cn' ||
url.hostname === 'www.amazon.in' || url.hostname === 'www.amazon.in' ||
url.hostname === 'www.amazon.au' url.hostname === 'www.amazon.au'
; };
exports.summary = async (url: URL.Url) => { export async function summary (url: URL.Url) {
const res = await client.fetch(url.href); const res = await client.fetch(url.href);
const $: any = res.$; const $: any = res.$;

View File

@ -4,10 +4,12 @@ import * as debug from 'debug';
const log = debug('summaly:plugins:wikipedia'); const log = debug('summaly:plugins:wikipedia');
exports.test = (url: URL.Url) => export function test (url: URL.Url) {
/\.wikipedia\.org$/.test(url.hostname); return /\.wikipedia\.org$/.test(url.hostname);
};
exports.summary = (url: URL.Url) => new Promise((res, rej) => { export function summary (url: URL.Url) {
return new Promise((res, rej) => {
const lang = url.host.split('.')[0]; const lang = url.host.split('.')[0];
const title = url.pathname.split('/')[2]; const title = url.pathname.split('/')[2];
const endpoint = `https://${lang}.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&titles=${encodeURIComponent(title)}`; const endpoint = `https://${lang}.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&titles=${encodeURIComponent(title)}`;
@ -28,4 +30,5 @@ exports.summary = (url: URL.Url) => new Promise((res, rej) => {
sitename: 'Wikipedia' sitename: 'Wikipedia'
}); });
}); });
}); });
};