mirror of
https://github.com/misskey-dev/summaly.git
synced 2025-05-11 16:47:22 +09:00
Merge pull request #8 from armchair-philosophy/escape-commonJS
escape from commonJS concept
This commit is contained in:
commit
af20d95845
@ -4,9 +4,13 @@ import ISummary from './isummary';
|
||||
import IPlugin from './iplugin';
|
||||
import general from './general';
|
||||
|
||||
/* plugins */
|
||||
import * as amazon from './plugins/amazon';
|
||||
import * as wikipedia from './plugins/wikipedia';
|
||||
|
||||
const plugins: IPlugin[] = [
|
||||
require('./plugins/amazon'),
|
||||
require('./plugins/wikipedia')
|
||||
amazon,
|
||||
wikipedia
|
||||
];
|
||||
|
||||
export default async (url: string): Promise<ISummary> => {
|
||||
|
@ -4,8 +4,8 @@ const client = require('cheerio-httpcli');
|
||||
client.referer = false;
|
||||
client.timeout = 10000;
|
||||
|
||||
exports.test = (url: URL.Url) =>
|
||||
url.hostname === 'www.amazon.com' ||
|
||||
export function test (url: URL.Url) {
|
||||
return url.hostname === 'www.amazon.com' ||
|
||||
url.hostname === 'www.amazon.co.jp' ||
|
||||
url.hostname === 'www.amazon.ca' ||
|
||||
url.hostname === 'www.amazon.com.br' ||
|
||||
@ -19,9 +19,9 @@ exports.test = (url: URL.Url) =>
|
||||
url.hostname === 'www.amazon.cn' ||
|
||||
url.hostname === 'www.amazon.in' ||
|
||||
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 $: any = res.$;
|
||||
|
||||
|
@ -4,28 +4,31 @@ import * as debug from 'debug';
|
||||
|
||||
const log = debug('summaly:plugins:wikipedia');
|
||||
|
||||
exports.test = (url: URL.Url) =>
|
||||
/\.wikipedia\.org$/.test(url.hostname);
|
||||
export function test (url: URL.Url) {
|
||||
return /\.wikipedia\.org$/.test(url.hostname);
|
||||
};
|
||||
|
||||
exports.summary = (url: URL.Url) => new Promise((res, rej) => {
|
||||
const lang = url.host.split('.')[0];
|
||||
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)}`;
|
||||
export function summary (url: URL.Url) {
|
||||
return new Promise((res, rej) => {
|
||||
const lang = url.host.split('.')[0];
|
||||
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)}`;
|
||||
|
||||
log(`lang is ${lang}`);
|
||||
log(`title is ${title}`);
|
||||
log(`endpoint is ${endpoint}`);
|
||||
log(`lang is ${lang}`);
|
||||
log(`title is ${title}`);
|
||||
log(`endpoint is ${endpoint}`);
|
||||
|
||||
request(endpoint, (err, _, body) => {
|
||||
log(body);
|
||||
body = JSON.parse(body);
|
||||
const info = body.query.pages[Object.keys(body.query.pages)[0]];
|
||||
res({
|
||||
title: info.title,
|
||||
icon: 'https://wikipedia.org/static/favicon/wikipedia.ico',
|
||||
description: info.extract,
|
||||
thumbnail: `https://wikipedia.org/static/images/project-logos/${lang}wiki.png`,
|
||||
sitename: 'Wikipedia'
|
||||
request(endpoint, (err, _, body) => {
|
||||
log(body);
|
||||
body = JSON.parse(body);
|
||||
const info = body.query.pages[Object.keys(body.query.pages)[0]];
|
||||
res({
|
||||
title: info.title,
|
||||
icon: 'https://wikipedia.org/static/favicon/wikipedia.ico',
|
||||
description: info.extract,
|
||||
thumbnail: `https://wikipedia.org/static/images/project-logos/${lang}wiki.png`,
|
||||
sitename: 'Wikipedia'
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user