Skip to content

Commit

Permalink
add nytimes morning post (DIYgod#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
yangkghjh authored and DIYgod committed Jun 2, 2018
1 parent 4606696 commit 8b490af
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇
- yande.re
- posts
- Popular Recent Posts
- 纽约时报
- 新闻早报

## 鸣谢

Expand Down
16 changes: 16 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1030,3 +1030,19 @@ GitHub 官方也提供了一些 RSS:
since,时间跨度,可在 [Trending 页](https://github.com/trending/javascript?since=monthly) URL 中找到,可选 daily weekly monthly

language,语言,可在 [Trending 页](https://github.com/trending/javascript?since=monthly) URL 中找到

## 纽约时报

::: tip 提示

纽约时报 RSS: https://cn.nytimes.com/rss/

:::

### 新闻早报

举例: [https://rsshub.app/nytimes/morning_post](https://rsshub.app/nytimes/morning_post)

路由: `/nytimes/morning_post`

参数: 无
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"path-to-regexp": "2.2.1",
"readall": "1.0.0",
"redis": "2.8.0",
"rss-parser": "^3.1.3",
"twit": "2.2.9",
"winston": "3.0.0-rc5"
},
Expand Down
3 changes: 3 additions & 0 deletions router.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,7 @@ router.get('/yande.re/post/popular_recent', require('./routes/yande.re/post_popu
router.get('/yande.re/post/:tags', require('./routes/yande.re/post'));
router.get('/yande.re/post/popular_recent/:period', require('./routes/yande.re/post_popular_recent'));

// nytimes
router.get('/nytimes/morning_post', require('./routes/nytimes/morning_post'));

module.exports = router;
25 changes: 25 additions & 0 deletions routes/nytimes/morning_post.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const Parser = require('rss-parser');
const parser = new Parser();

module.exports = async (ctx) => {
const feed = await parser.parseURL('https://cn.nytimes.com/rss/');
const items = [];
feed.items.forEach((item) => {
if (item.title.startsWith('早报:')) {
items.push({
title: item.title,
description: item.content,
pubDate: item.pubDate,
guid: item.guid,
link: item.link,
});
}
});

ctx.state.data = {
title: '纽约时报 新闻早报',
link: encodeURI('https://cn.nytimes.com/search?query=%E6%97%A9%E6%8A%A5&lang=&dt=json&from=0&size=10'),
description: '纽约时报 新闻早报',
item: items,
};
};
20 changes: 19 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6349,6 +6349,13 @@ ripemd160@^2.0.0, ripemd160@^2.0.1:
hash-base "^3.0.0"
inherits "^2.0.1"

rss-parser@^3.1.3:
version "3.1.3"
resolved "http://registry.npm.taobao.org/rss-parser/download/rss-parser-3.1.3.tgz#ad56491623d66ccce2f4f5c833377542c0f0c4f5"
dependencies:
entities "^1.1.1"
xml2js "^0.4.17"

run-async@^2.2.0:
version "2.3.0"
resolved "https://registry.npmjs.org/run-async/-/run-async-2.3.0.tgz#0371ab4ae0bdd720d4166d7dfda64ff7a445a6c0"
Expand Down Expand Up @@ -6395,7 +6402,7 @@ [email protected]:
version "0.5.8"
resolved "https://registry.npmjs.org/sax/-/sax-0.5.8.tgz#d472db228eb331c2506b0e8c15524adb939d12c1"

sax@^1.2.4, sax@~1.2.1:
sax@>=0.6.0, sax@^1.2.4, sax@~1.2.1:
version "1.2.4"
resolved "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"

Expand Down Expand Up @@ -7777,6 +7784,17 @@ xml-name-validator@^3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-3.0.0.tgz#6ae73e06de4d8c6e47f9fb181f78d648ad457c6a"

xml2js@^0.4.17:
version "0.4.19"
resolved "http://registry.npm.taobao.org/xml2js/download/xml2js-0.4.19.tgz#686c20f213209e94abf0d1bcf1efaa291c7827a7"
dependencies:
sax ">=0.6.0"
xmlbuilder "~9.0.1"

xmlbuilder@~9.0.1:
version "9.0.7"
resolved "http://registry.npm.taobao.org/xmlbuilder/download/xmlbuilder-9.0.7.tgz#132ee63d2ec5565c557e20f4c22df9aca686b10d"

xtend@^4.0.0, xtend@~4.0.1:
version "4.0.1"
resolved "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af"
Expand Down

0 comments on commit 8b490af

Please sign in to comment.