mirror of
https://github.com/misskey-dev/summaly.git
synced 2025-08-02 22:36:34 +09:00
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
unreleased
|
||||
------------------
|
||||
* Add `followRedirects` option #16
|
||||
* Add `url` property to result #15
|
||||
|
||||
1.5.0 / 2017-01-31
|
||||
|
28
README.md
28
README.md
@ -11,15 +11,24 @@ Installation
|
||||
|
||||
Usage
|
||||
-----
|
||||
``` javascript
|
||||
summaly(url[, opts])
|
||||
```
|
||||
(url: string) => Promise<{
|
||||
title: string;
|
||||
icon: string;
|
||||
description: string;
|
||||
thumbnail: string;
|
||||
sitename: string;
|
||||
}>
|
||||
```
|
||||
|
||||
### Options
|
||||
| Property | Type | Description | Default |
|
||||
| :------------------ | :-------- | :-------------------------- | :------ |
|
||||
| **followRedirects** | *boolean* | リダイレクトを解決するかどうか | `true` |
|
||||
|
||||
### Returns
|
||||
| Property | Type | Description |
|
||||
| :-------------- | :------- | :--------------------------------------- |
|
||||
| **description** | *string* | The description of そのWebページ |
|
||||
| **icon** | *string* | The url of the icon of そのWebページ |
|
||||
| **sitename** | *string* | The name of そのWebサイト |
|
||||
| **thumbnail** | *string* | The url of the thumbnail of そのWebページ |
|
||||
| **title** | *string* | The title of そのWebページ |
|
||||
| **url** | *string* | The url of そのWebページ |
|
||||
|
||||
### Example
|
||||
``` javascript
|
||||
@ -34,7 +43,8 @@ console.log(summary); // will be ... ↓
|
||||
icon: 'http://livedoor.blogimg.jp/tmg24news/imgs/9/5/favicon.ico',
|
||||
description: '1:以下、名無しにかわりましてVIPがお送りします:2013/03/30(土) 14:57:29.09 ID:An34eOmY0モバP「反論が あるやつもいるかもしれない」 モバP「だが俺の主張も聞いてほしい! お漏らしさせるならありすが一番だ!」 日菜子「むふふ……いきなりそんなことを大声で',
|
||||
thumbnail: 'http://livedoor.blogimg.jp/tmg24news/imgs/8/d/8df6e1a0-s.jpg',
|
||||
sitename: 'エレファント速報:SSまとめブログ'
|
||||
sitename: 'エレファント速報:SSまとめブログ',
|
||||
url: 'http://elephant.2chblog.jp/archives/52025138.html'
|
||||
}
|
||||
*/
|
||||
```
|
||||
|
20
src/index.ts
20
src/index.ts
@ -14,14 +14,26 @@ const plugins: IPlugin[] = require('require-all')({
|
||||
dirname: __dirname + '/plugins'
|
||||
});
|
||||
|
||||
export interface IOptions {
|
||||
/**
|
||||
* リダイレクトを追跡するか否か
|
||||
*/
|
||||
followRedirects: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Summary an web page
|
||||
* @param {string} url URL of web page you want to summary
|
||||
* @return {Promise<ISummary>} Promised summary
|
||||
* @param {string} url URL of web page you want to summary
|
||||
* @param {IOptions} options The options
|
||||
* @return {Promise<ISummary>} Promised summary
|
||||
*/
|
||||
export default async (url: string): Promise<ISummary> => {
|
||||
export default async (url: string, options: IOptions): Promise<ISummary> => {
|
||||
const opts = Object.assign({
|
||||
followRedirects: true
|
||||
}, options);
|
||||
|
||||
// Follow redirects
|
||||
const actualUrl = await tracer(url);
|
||||
const actualUrl = opts.followRedirects ? await tracer(url) : url;
|
||||
|
||||
const _url = URL.parse(actualUrl, true);
|
||||
|
||||
|
Reference in New Issue
Block a user