mirror of
https://github.com/misskey-dev/summaly.git
synced 2025-07-02 08:09:59 +09:00
3.0.1
This commit is contained in:
5
built/plugins/amazon.d.ts
vendored
Normal file
5
built/plugins/amazon.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
/// <reference types="node" />
|
||||
import * as URL from 'node:url';
|
||||
import summary from '../summary.js';
|
||||
export declare function test(url: URL.Url): boolean;
|
||||
export declare function summarize(url: URL.Url): Promise<summary>;
|
43
built/plugins/amazon.js
Normal file
43
built/plugins/amazon.js
Normal file
@ -0,0 +1,43 @@
|
||||
import { scpaping } from '../utils/got.js';
|
||||
export function test(url) {
|
||||
return 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';
|
||||
}
|
||||
export async function summarize(url) {
|
||||
const res = await scpaping(url.href);
|
||||
const $ = res.$;
|
||||
const title = $('#title').text();
|
||||
const description = $('#productDescription').text() ||
|
||||
$('meta[name="description"]').attr('content');
|
||||
const thumbnail = $('#landingImage').attr('src');
|
||||
const playerUrl = $('meta[property="twitter:player"]').attr('content') ||
|
||||
$('meta[name="twitter:player"]').attr('content');
|
||||
const playerWidth = $('meta[property="twitter:player:width"]').attr('content') ||
|
||||
$('meta[name="twitter:player:width"]').attr('content');
|
||||
const playerHeight = $('meta[property="twitter:player:height"]').attr('content') ||
|
||||
$('meta[name="twitter:player:height"]').attr('content');
|
||||
return {
|
||||
title: title ? title.trim() : null,
|
||||
icon: 'https://www.amazon.com/favicon.ico',
|
||||
description: description ? description.trim() : null,
|
||||
thumbnail: thumbnail ? thumbnail.trim() : null,
|
||||
player: {
|
||||
url: playerUrl || null,
|
||||
width: playerWidth ? parseInt(playerWidth) : null,
|
||||
height: playerHeight ? parseInt(playerHeight) : null
|
||||
},
|
||||
sitename: 'Amazon'
|
||||
};
|
||||
}
|
2
built/plugins/index.d.ts
vendored
Normal file
2
built/plugins/index.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import { IPlugin } from '@/iplugin.js';
|
||||
export declare const plugins: IPlugin[];
|
6
built/plugins/index.js
Normal file
6
built/plugins/index.js
Normal file
@ -0,0 +1,6 @@
|
||||
import * as amazon from './amazon.js';
|
||||
import * as wikipedia from './wikipedia.js';
|
||||
export const plugins = [
|
||||
amazon,
|
||||
wikipedia,
|
||||
];
|
5
built/plugins/wikipedia.d.ts
vendored
Normal file
5
built/plugins/wikipedia.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
/// <reference types="node" />
|
||||
import * as URL from 'node:url';
|
||||
import summary from '../summary.js';
|
||||
export declare function test(url: URL.Url): boolean;
|
||||
export declare function summarize(url: URL.Url): Promise<summary>;
|
36
built/plugins/wikipedia.js
Normal file
36
built/plugins/wikipedia.js
Normal file
@ -0,0 +1,36 @@
|
||||
import { get } from '../utils/got.js';
|
||||
import debug from 'debug';
|
||||
import clip from './../utils/clip.js';
|
||||
const log = debug('summaly:plugins:wikipedia');
|
||||
export function test(url) {
|
||||
if (!url.hostname)
|
||||
return false;
|
||||
return /\.wikipedia\.org$/.test(url.hostname);
|
||||
}
|
||||
export async function summarize(url) {
|
||||
const lang = url.host ? url.host.split('.')[0] : null;
|
||||
const title = url.pathname ? url.pathname.split('/')[2] : null;
|
||||
const endpoint = `https://${lang}.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro=&explaintext=&titles=${title}`;
|
||||
log(`lang is ${lang}`);
|
||||
log(`title is ${title}`);
|
||||
log(`endpoint is ${endpoint}`);
|
||||
let body = await get(endpoint);
|
||||
body = JSON.parse(body);
|
||||
log(body);
|
||||
if (!('query' in body) || !('pages' in body.query)) {
|
||||
throw 'fetch failed';
|
||||
}
|
||||
const info = body.query.pages[Object.keys(body.query.pages)[0]];
|
||||
return {
|
||||
title: info.title,
|
||||
icon: 'https://wikipedia.org/static/favicon/wikipedia.ico',
|
||||
description: clip(info.extract, 300),
|
||||
thumbnail: `https://wikipedia.org/static/images/project-logos/${lang}wiki.png`,
|
||||
player: {
|
||||
url: null,
|
||||
width: null,
|
||||
height: null
|
||||
},
|
||||
sitename: 'Wikipedia'
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user