mirror of
https://github.com/misskey-dev/summaly.git
synced 2025-05-10 16:17:23 +09:00
This commit is contained in:
parent
50c88af9ed
commit
70bf14ad35
@ -1,5 +1,6 @@
|
|||||||
unreleased
|
unreleased
|
||||||
------------------
|
------------------
|
||||||
|
* Add user-defined plugin support #22
|
||||||
* Add `followRedirects` option #16
|
* Add `followRedirects` option #16
|
||||||
* Add `url` property to result #15
|
* Add `url` property to result #15
|
||||||
|
|
||||||
|
33
src/index.ts
33
src/index.ts
@ -4,34 +4,49 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import * as URL from 'url';
|
import * as URL from 'url';
|
||||||
|
import requireAll from 'require-all';
|
||||||
import tracer from 'trace-redirect';
|
import tracer from 'trace-redirect';
|
||||||
import ISummary from './isummary';
|
import ISummary from './isummary';
|
||||||
import IPlugin from './iplugin';
|
import IPlugin from './iplugin';
|
||||||
import general from './general';
|
import general from './general';
|
||||||
|
|
||||||
// Load plugins
|
// Load builtin plugins
|
||||||
const plugins: IPlugin[] = require('require-all')({
|
const builtinPlugins = requireAll({
|
||||||
dirname: __dirname + '/plugins'
|
dirname: __dirname + '/plugins'
|
||||||
});
|
}) as IPlugin[];
|
||||||
|
|
||||||
export interface IOptions {
|
export interface IOptions {
|
||||||
/**
|
/**
|
||||||
* リダイレクトを追跡するか否か
|
* リダイレクトを追跡するか否か
|
||||||
*/
|
*/
|
||||||
followRedirects: boolean;
|
followRedirects?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom Plugins
|
||||||
|
*/
|
||||||
|
plugins?: IPlugin[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Result = ISummary & {
|
||||||
|
url: string;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Summary an web page
|
* Summary an web page
|
||||||
* @param {string} url URL of web page you want to summary
|
* @param {string} url URL of web page you want to summary
|
||||||
* @param {IOptions} options The options
|
* @param {IOptions} options The options
|
||||||
* @return {Promise<ISummary>} Promised summary
|
* @return {Promise<Result>} Promised summary
|
||||||
*/
|
*/
|
||||||
export default async (url: string, options: IOptions): Promise<ISummary> => {
|
export default async (url: string, options: IOptions): Promise<Result> => {
|
||||||
const opts = Object.assign({
|
const opts = Object.assign({
|
||||||
followRedirects: true
|
followRedirects: true,
|
||||||
|
plugins: null
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
|
const plugins = Object.keys(builtinPlugins)
|
||||||
|
.map(key => builtinPlugins[key])
|
||||||
|
.concat(opts.plugins || []);
|
||||||
|
|
||||||
// Follow redirects
|
// Follow redirects
|
||||||
const actualUrl = opts.followRedirects ? await tracer(url) : url;
|
const actualUrl = opts.followRedirects ? await tracer(url) : url;
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ interface ISummary {
|
|||||||
sitename: string;
|
sitename: string;
|
||||||
thumbnail: string;
|
thumbnail: string;
|
||||||
title: string;
|
title: string;
|
||||||
url: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default ISummary;
|
export default ISummary;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user