This commit is contained in:
syuilo
2017-02-04 15:57:02 +09:00
parent 382e963732
commit 2a09c6c1cb
3 changed files with 36 additions and 13 deletions

View File

@ -1,5 +1,6 @@
unreleased
------------------
* Add `followRedirects` option #16
* Add `url` property to result #15
1.5.0 / 2017-01-31

View File

@ -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「だが俺の主張も聞いてほしい! お漏らしさせるならありすが一番だ!」 日菜子「むふふ……いきなりそんなことを大声で',
thumbnail: 'http://livedoor.blogimg.jp/tmg24news/imgs/8/d/8df6e1a0-s.jpg',
sitename: 'エレファント速報SSまとめブログ'
sitename: 'エレファント速報SSまとめブログ',
url: 'http://elephant.2chblog.jp/archives/52025138.html'
}
*/
```

View File

@ -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);