Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
syuilo committed Feb 4, 2017
1 parent 382e963 commit 2a09c6c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
unreleased
------------------
* Add `followRedirects` option #16
* Add `url` property to result #15

1.5.0 / 2017-01-31
Expand Down
28 changes: 19 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
}
*/
```
Expand Down
20 changes: 16 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 2a09c6c

Please sign in to comment.