From 49de384d2ec458e1bf0e3a02e29d9206377139a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=95=E3=81=8F=E3=82=89?= Date: Thu, 17 May 2018 10:52:29 +0800 Subject: [PATCH] feat: add prettier and commit hooks (#144) * feat: add prettier and commit hooks * style(*): prettier format * fix(eslint): parsing error: Unexpected token ... * style(eslint): eslint --fix * style(bilibili): fix `no-undef` and `no-unused-vars` * style(jiandan): fix eqeqeq * style(pixiv): disable `no-constant-condition` rule for eslint * fix(pixiv): use template string * style(toutiao): remove unused variables * style(weibo): use `forEach` instead of `map` The array has no return value, you should use `forEach` instead of `map` * chore(hooks): add eslint hooks * chore(hooks): switch from husky to yorkie * style(zhihu): prettier format * style(docs): fix vuepress custom container https://vuepress.vuejs.org/guide/markdown.html#custom-containers * chore(prettier): set a more reasonable `printWidth` value * style(*): better prettier format --- .editorconfig | 39 ++++++ .eslintrc | 15 +-- .gitignore | 3 - .prettierignore | 1 + .prettierrc | 7 ++ README.md | 192 +++++++++++++++--------------- app.json | 73 ++++++------ config.js | 17 +-- docs/.vuepress/config.js | 17 +-- docs/README.md | 116 +++++++++--------- docs/install/README.md | 68 ++++++----- docs/joinus/README.md | 8 +- docs/support/README.md | 16 +-- index.js | 2 +- middleware/filter.js | 8 +- middleware/header.js | 2 +- middleware/lru-cache.js | 34 +++--- middleware/onerror.js | 2 +- middleware/redis-cache.js | 59 ++++----- middleware/template.js | 2 +- middleware/utf8.js | 2 +- package.json | 27 ++++- process.json | 20 ++-- router.js | 2 +- routes/bilibili/bangumi.js | 20 ++-- routes/bilibili/coin.js | 23 ++-- routes/bilibili/dynamic.js | 14 +-- routes/bilibili/fav.js | 27 +++-- routes/bilibili/followers.js | 16 +-- routes/bilibili/followings.js | 16 +-- routes/bilibili/linkNews.js | 35 +++--- routes/bilibili/liveArea.js | 41 ++++--- routes/bilibili/liveRoom.js | 25 ++-- routes/bilibili/liveSearch.js | 22 ++-- routes/bilibili/partion.js | 20 ++-- routes/bilibili/reply.js | 14 +-- routes/bilibili/video.js | 25 ++-- routes/biquge/chapter.js | 24 ++-- routes/dapenti/tugua.js | 34 +++--- routes/disqus/posts.js | 12 +- routes/dockone/weekly.js | 29 +++-- routes/douban/later.js | 4 +- routes/douban/playing.js | 6 +- routes/douban/ustop.js | 4 +- routes/express/express.js | 8 +- routes/geektime/column.js | 20 ++-- routes/instagram/user.js | 26 ++-- routes/jandan/pic.js | 44 ++++--- routes/jianshu/collection.js | 28 +++-- routes/jianshu/home.js | 28 +++-- routes/jianshu/monthly.js | 28 +++-- routes/jianshu/user.js | 28 +++-- routes/jianshu/weekly.js | 28 +++-- routes/jike/topic.js | 27 +++-- routes/jike/user.js | 55 +++++---- routes/juejin/category.js | 27 +++-- routes/mzitu/category.js | 32 ++--- routes/mzitu/post.js | 112 ++++++++--------- routes/mzitu/tag.js | 32 ++--- routes/mzitu/tags.js | 61 +++++----- routes/ncm/artist.js | 8 +- routes/ncm/playlist.js | 24 ++-- routes/ncm/userplaylist.js | 10 +- routes/pixiv/api/getBookmarks.js | 29 +++-- routes/pixiv/api/getIllusts.js | 28 ++--- routes/pixiv/api/getRanking.js | 38 +++--- routes/pixiv/api/getUserDetail.js | 27 ++--- routes/pixiv/bookmarks.js | 11 +- routes/pixiv/constants.js | 4 +- routes/pixiv/ranking.js | 54 ++++----- routes/pixiv/token.js | 31 ++--- routes/pixiv/user.js | 6 +- routes/tieba/forum.js | 36 +++--- routes/toutiao/today.js | 43 +++++-- routes/toutiao/user.js | 52 +++++--- routes/tucaoqq/post.js | 11 +- routes/twitter/user.js | 6 +- routes/weibo/keyword.js | 8 +- routes/weibo/user.js | 12 +- routes/weibo/user2.js | 15 ++- routes/weibo/utils.js | 8 +- routes/youtube/channel.js | 8 +- routes/youtube/user.js | 8 +- routes/zhihu/activities.js | 132 ++++++++++---------- routes/zhihu/answers.js | 22 ++-- routes/zhihu/collection.js | 30 +++-- routes/zhihu/daily.js | 20 ++-- routes/zhihu/zhuanlan.js | 12 +- routes/ziroom/room.js | 33 +++-- utils/logger.js | 19 +-- utils/md5.js | 7 +- utils/wait.js | 8 +- yarn.lock | 19 ++- 93 files changed, 1378 insertions(+), 1128 deletions(-) create mode 100644 .editorconfig create mode 100644 .prettierignore create mode 100644 .prettierrc diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000000000..6ec4eba983adb4 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,39 @@ +# http://editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +# Use 4 spaces for the Python files +[*.py] +indent_size = 4 +max_line_length = 80 + +# The JSON files contain newlines inconsistently +[*.json] +insert_final_newline = ignore + +# Minified JavaScript files shouldn't be changed +[**.min.js] +indent_style = ignore +insert_final_newline = ignore + +# Makefiles always use tabs for indentation +[Makefile] +indent_style = tab + +# Batch files use tabs for indentation +[*.bat] +indent_style = tab + +[*.md] +trim_trailing_whitespace = false + +# Matches the exact files either package.json or .travis.yml +[{package.json,.travis.yml}] +indent_size = 2 diff --git a/.eslintrc b/.eslintrc index 76c4c425edfa93..56e88f4b898c20 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,8 +1,12 @@ { - "extends": "eslint:recommended", + "extends": ["eslint:recommended", "plugin:prettier/recommended"], + "plugins": ["prettier"], "parserOptions": { "ecmaVersion": 2017, - "sourceType": "module" + "sourceType": "module", + "ecmaFeatures": { + "experimentalObjectRestSpread": true + } }, "env": { "node": true, @@ -10,7 +14,6 @@ }, "rules": { "no-console": 0, - "no-extra-parens": 1, "block-scoped-var": 1, "curly": 1, "eqeqeq": 1, @@ -21,7 +24,6 @@ "comma-spacing": 1, "comma-style": 1, "func-call-spacing": 1, - "indent": 1, "keyword-spacing": 1, "linebreak-style": 1, "lines-around-comment": 1, @@ -32,14 +34,12 @@ "prefer-const": 1, "no-unsafe-negation": 1, "array-callback-return": 1, - "dot-location": 1, "dot-notation": 1, "no-eval": 1, "no-extend-native": 1, "no-extra-label": 1, "semi": 1, "space-before-blocks": 1, - "space-before-function-paren": 1, "space-in-parens": 1, "space-unary-ops": 1, "spaced-comment": 1, @@ -52,6 +52,7 @@ "rest-spread-spacing": 1, "no-trailing-spaces": 1, "quotes": [1, "single"], - "no-control-regex": 0 + "no-control-regex": 0, + "prettier/prettier": 0 } } diff --git a/.gitignore b/.gitignore index 8b0c6a7c469834..4ed07562e76b1d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,3 @@ npm-debug.log error.log combined.log .vscode -.prettierrc -.prettierignore -.editorconfig diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000000000..ec6d3cdd7f5b08 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +package.json diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 00000000000000..8fa3efce4fb391 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,7 @@ +{ + "printWidth": 233, + "tabWidth": 4, + "singleQuote": true, + "trailingComma": "es5", + "arrowParens": "always" +} diff --git a/README.md b/README.md index 4a674fb68354c2..c6a3ce44b73d06 100644 --- a/README.md +++ b/README.md @@ -13,90 +13,90 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 当前支持列表: -- bilibili - - 番剧 - - UP 主投稿 - - UP 主动态 - - UP 主收藏夹 - - UP 主投币视频 - - UP 主粉丝 - - UP 主关注用户 - - 分区视频 - - 视频评论 - - link 公告 - - 直播开播 - - 直播搜索 - - 直播分区 -- 微博 - - 博主 - - 关键词 -- 即刻 - - 主题 - - 用户动态 -- 网易云音乐 - - 歌单歌曲 - - 用户歌单 - - 歌手专辑 -- 掘金 - - 分类 -- 简书 - - 首页 - - 7 日热门 - - 30 日热门 - - 专题 - - 作者 -- 知乎 - - 收藏夹 - - 用户动态 - - 用户回答 - - 专栏 - - 知乎日报 -- 自如 - - 房源 -- 快递 -- 贴吧 - - 帖子列表 -- 妹子图 - - 首页(最新) - - 分类 - - 所有专题 - - 专题详情 - - 详情 -- pixiv - - 用户收藏 - - 用户动态 - - 排行榜 -- 豆瓣 - - 正在上映的电影 - - 正在上映的高分电影 - - 即将上映的电影 - - 北美票房榜 -- 煎蛋 - - 无聊图 -- 喷嚏 - - 图卦 -- Dockone - - 周报 -- 腾讯吐个槽 - - 吐槽新帖 -- 笔趣阁 - - 小说章节 -- 开发者头条 - - 今天头条 - - 独家号 -- 极客时间 - - 专栏文章 -- 央视新闻 - - 专题 -- Disqus - - 评论 -- Twitter - - 用户 -- Instagram - - 用户 -- Youtube - - 用户 - - 频道 +* bilibili + * 番剧 + * UP 主投稿 + * UP 主动态 + * UP 主收藏夹 + * UP 主投币视频 + * UP 主粉丝 + * UP 主关注用户 + * 分区视频 + * 视频评论 + * link 公告 + * 直播开播 + * 直播搜索 + * 直播分区 +* 微博 + * 博主 + * 关键词 +* 即刻 + * 主题 + * 用户动态 +* 网易云音乐 + * 歌单歌曲 + * 用户歌单 + * 歌手专辑 +* 掘金 + * 分类 +* 简书 + * 首页 + * 7 日热门 + * 30 日热门 + * 专题 + * 作者 +* 知乎 + * 收藏夹 + * 用户动态 + * 用户回答 + * 专栏 + * 知乎日报 +* 自如 + * 房源 +* 快递 +* 贴吧 + * 帖子列表 +* 妹子图 + * 首页(最新) + * 分类 + * 所有专题 + * 专题详情 + * 详情 +* pixiv + * 用户收藏 + * 用户动态 + * 排行榜 +* 豆瓣 + * 正在上映的电影 + * 正在上映的高分电影 + * 即将上映的电影 + * 北美票房榜 +* 煎蛋 + * 无聊图 +* 喷嚏 + * 图卦 +* Dockone + * 周报 +* 腾讯吐个槽 + * 吐槽新帖 +* 笔趣阁 + * 小说章节 +* 开发者头条 + * 今天头条 + * 独家号 +* 极客时间 + * 专栏文章 +* 央视新闻 + * 专题 +* Disqus + * 评论 +* Twitter + * 用户 +* Instagram + * 用户 +* Youtube + * 用户 + * 频道 ## 参与我们 @@ -104,15 +104,15 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 ### 提交新的 RSS 内容 -1. 在 [/router.js](https://github.com/DIYgod/RSSHub/blob/master/router.js) 里添加路由 +1. 在 [/router.js](https://github.com/DIYgod/RSSHub/blob/master/router.js) 里添加路由 -1. 在 [/routes/](https://github.com/DIYgod/RSSHub/tree/master/routes) 中的路由对应路径添加获取 RSS 内容的脚本 +1. 在 [/routes/](https://github.com/DIYgod/RSSHub/tree/master/routes) 中的路由对应路径添加获取 RSS 内容的脚本 -1. 更新 README 和文档: [/README.md](https://github.com/DIYgod/RSSHub/blob/master/README.md) [/docs/README.md](https://github.com/DIYgod/RSSHub/blob/master/docs/README.md) +1. 更新 README 和文档: [/README.md](https://github.com/DIYgod/RSSHub/blob/master/README.md) [/docs/README.md](https://github.com/DIYgod/RSSHub/blob/master/docs/README.md) ### 参与讨论 -1. [Telegram 群](https://t.me/rsshub) +1. [Telegram 群](https://t.me/rsshub) ## 部署 @@ -128,24 +128,24 @@ RSSHub 是采用 MIT 许可的开源项目,使用完全免费。 但是随着 我们通过以下方式接受赞助: -- [微信支付](https://i.imgur.com/aq6PtWa.png) -- [支付宝](https://i.imgur.com/wv1Pj2k.png) -- [Paypal](https://www.paypal.me/DIYgod) -- 比特币: 13CwQLHzPYm2tewNMSJBeArbbRM5NSmCD1 +* [微信支付](https://i.imgur.com/aq6PtWa.png) +* [支付宝](https://i.imgur.com/wv1Pj2k.png) +* [Paypal](https://www.paypal.me/DIYgod) +* 比特币: 13CwQLHzPYm2tewNMSJBeArbbRM5NSmCD1 ### 周期性赞助 周期性赞助可以获得额外的回报,比如你的名字 会出现在 RSSHub 的 GitHub 仓库和现在我们的官网中。 -- 通过 [OpenCollective](https://opencollective.com/RSSHub) 赞助成为 backer 或 sponsor -- 通过 [Patreon](https://www.patreon.com/DIYgod) 赞助成为 backer -- 给我们发邮件联系赞助事宜: i#html.love +* 通过 [OpenCollective](https://opencollective.com/RSSHub) 赞助成为 backer 或 sponsor +* 通过 [Patreon](https://www.patreon.com/DIYgod) 赞助成为 backer +* 给我们发邮件联系赞助事宜: i#html.love ## 鸣谢 ### Sponsors -- [Sayori Studio](https://t.me/SayoriStudio) +* [Sayori Studio](https://t.me/SayoriStudio) ### Contributors diff --git a/app.json b/app.json index 8ad1353633cd4d..1c25e4eeeb371b 100644 --- a/app.json +++ b/app.json @@ -1,39 +1,38 @@ { - "name": "RSSHub", - "description": "Connect the world with RSS", - "repository": "https://github.com/DIYgod/RSSHub", - "website": "https://rsshub.js.org/", - "logo": "https://i.imgur.com/NZpRScX.png", - "keywords": ["RSS"], - "env": { - "PORT": { - "value": "80", - "required": false - }, - "PIXIV_USERNAME": { - "required": false - }, - "PIXIV_PASSWORD": { - "required": false - }, - "DISQUS_API_KEY": { - "required": false - }, - "TWITTER_CONSUMER_KEY": { - "required": false - }, - "TWITTER_CONSUMER_SECRET": { - "required": false - }, - "TWITTER_ACCESS_TOKEN": { - "required": false - }, - "TWITTER_ACCESS_TOKEN_SECRET": { - "required": false - }, - "YOUTUBE_KEY": { - "required": false - } - } + "name": "RSSHub", + "description": "Connect the world with RSS", + "repository": "https://github.com/DIYgod/RSSHub", + "website": "https://rsshub.js.org/", + "logo": "https://i.imgur.com/NZpRScX.png", + "keywords": ["RSS"], + "env": { + "PORT": { + "value": "80", + "required": false + }, + "PIXIV_USERNAME": { + "required": false + }, + "PIXIV_PASSWORD": { + "required": false + }, + "DISQUS_API_KEY": { + "required": false + }, + "TWITTER_CONSUMER_KEY": { + "required": false + }, + "TWITTER_CONSUMER_SECRET": { + "required": false + }, + "TWITTER_ACCESS_TOKEN": { + "required": false + }, + "TWITTER_ACCESS_TOKEN_SECRET": { + "required": false + }, + "YOUTUBE_KEY": { + "required": false + } + } } - diff --git a/config.js b/config.js index b79843bdad53e5..bb692d53dc1684 100644 --- a/config.js +++ b/config.js @@ -1,14 +1,15 @@ module.exports = { - port: process.env.PORT || 1200, // 监听端口 - cacheType: process.env.CACHE_TYPE || 'memory', // 缓存类型,支持 'memory' 和 'redis',设为空可以禁止缓存 - cacheExpire: process.env.CACHE_EXPIRE || 5 * 60, // 缓存时间,单位为秒 + port: process.env.PORT || 1200, // 监听端口 + cacheType: process.env.CACHE_TYPE || 'memory', // 缓存类型,支持 'memory' 和 'redis',设为空可以禁止缓存 + cacheExpire: process.env.CACHE_EXPIRE || 5 * 60, // 缓存时间,单位为秒 ua: process.env.UA || 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36', - listenInaddrAny: process.env.LISTEN_INADDR_ANY || 1, // 是否允许公网连接,取值 0 1 + listenInaddrAny: process.env.LISTEN_INADDR_ANY || 1, // 是否允许公网连接,取值 0 1 redis: { url: process.env.REDIS_URL || 'redis://localhost:6379/', - options: { // 支持这些参数 https://github.com/NodeRedis/node_redis#options-object-properties + options: { + // 支持这些参数 https://github.com/NodeRedis/node_redis#options-object-properties password: process.env.REDIS_PASSWORD || null, - } + }, }, pixiv: { client_id: 'MOBrBDS8blbauoSck0ZfDbtuzpyT', @@ -26,6 +27,6 @@ module.exports = { access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET, }, youtube: { - key: process.env.YOUTUBE_KEY - } + key: process.env.YOUTUBE_KEY, + }, }; diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index 2477766fed0a4f..2a0b9644e876a0 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -8,22 +8,23 @@ module.exports = { editLinks: true, editLinkText: '帮助我们改善此页面!', docsDir: 'docs', - nav: [{ + nav: [ + { text: '使用', - link: '/' + link: '/', }, { text: '参与我们', - link: '/joinus/' + link: '/joinus/', }, { text: '部署', - link: '/install/' + link: '/install/', }, { text: '支持 RSSHub', - link: '/support/' + link: '/support/', }, - ] - } -} \ No newline at end of file + ], + }, +}; diff --git a/docs/README.md b/docs/README.md index 2da1a502af632c..75cd3fba8e971c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -10,18 +10,20 @@ sidebar: auto RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇怪怪的内容生成 RSS 订阅源 ::: tip 提示 + 演示地址为 [rsshub.app](https://rsshub.app),缓存时间 10 分钟,可以随意使用 + ::: ## 内容过滤 可以使用以下 URL query 过滤出想要的内容,支持正则 -- filter: 过滤标题和描述 +* filter: 过滤标题和描述 -- filter_title: 过滤标题 +* filter_title: 过滤标题 -- filter_description: 过滤描述 +* filter_description: 过滤描述 举例: [https://rsshub.app/bilibili/user/coin/2267573?filter=微小微|赤九玖|暴走大事件](https://rsshub.app/bilibili/user/coin/2267573?filter=微小微|赤九玖|暴走大事件) @@ -93,81 +95,81 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 动画 -| MAD·AMV | MMD·3D | 短片·手书·配音 | 综合 | -| ------- | ------ | -------- | ---- | -| 24 | 25 | 47 | 27 | +| MAD·AMV | MMD·3D | 短片·手书·配音 | 综合 | +| ------- | ------ | -------------- | ---- | +| 24 | 25 | 47 | 27 | 番剧 -| 连载动画 | 完结动画 | 资讯 | 官方延伸 | -| ---- | ---- | ---- | ---- | -| 33 | 32 | 51 | 152 | +| 连载动画 | 完结动画 | 资讯 | 官方延伸 | +| -------- | -------- | ---- | -------- | +| 33 | 32 | 51 | 152 | 国创 -| 国产动画 | 国产原创相关 | 布袋戏 | 资讯 | -| ---- | ------ | ---- | ---- | -| 153 | 168 | 169 | 170 | +| 国产动画 | 国产原创相关 | 布袋戏 | 资讯 | +| -------- | ------------ | ------ | ---- | +| 153 | 168 | 169 | 170 | 音乐 -| 原创音乐 | 翻唱 | VOCALOID·UTAU | 演奏 | 三次元音乐 | OP/ED/OST | 音乐选集 | -| ---- | ---- | ------------- | ---- | ----- | --------- | ---- | -| 28 | 31 | 30 | 59 | 29 | 54 | 130 | +| 原创音乐 | 翻唱 | VOCALOID·UTAU | 演奏 | 三次元音乐 | OP/ED/OST | 音乐选集 | +| -------- | ---- | ------------- | ---- | ---------- | --------- | -------- | +| 28 | 31 | 30 | 59 | 29 | 54 | 130 | 舞蹈 -| 宅舞 | 三次元舞蹈 | 舞蹈教程 | -| ---- | ----- | ---- | -| 20 | 154 | 156 | +| 宅舞 | 三次元舞蹈 | 舞蹈教程 | +| ---- | ---------- | -------- | +| 20 | 154 | 156 | 游戏 -| 单机游戏 | 电子竞技 | 手机游戏 | 网络游戏 | 桌游棋牌 | GMV | 音游 | Mugen | -| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ----- | -| 17 | 171 | 172 | 65 | 173 | 121 | 136 | 19 | +| 单机游戏 | 电子竞技 | 手机游戏 | 网络游戏 | 桌游棋牌 | GMV | 音游 | Mugen | +| -------- | -------- | -------- | -------- | -------- | --- | ---- | ----- | +| 17 | 171 | 172 | 65 | 173 | 121 | 136 | 19 | 科技 -| 趣味科普人文 | 野生技术协会 | 演讲·公开课 | 星海 | 数码 | 机械 | 汽车 | -| ------ | ------ | ------ | ---- | ---- | ---- | ---- | -| 124 | 122 | 39 | 96 | 95 | 98 | 176 | +| 趣味科普人文 | 野生技术协会 | 演讲·公开课 | 星海 | 数码 | 机械 | 汽车 | +| ------------ | ------------ | ----------- | ---- | ---- | ---- | ---- | +| 124 | 122 | 39 | 96 | 95 | 98 | 176 | 生活 -| 搞笑 | 日常 | 美食圈 | 动物圈 | 手工 | 绘画 | ASMR | 运动 | 其他 | -| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | -| 138 | 21 | 76 | 75 | 161 | 162 | 175 | 163 | 174 | +| 搞笑 | 日常 | 美食圈 | 动物圈 | 手工 | 绘画 | ASMR | 运动 | 其他 | +| ---- | ---- | ------ | ------ | ---- | ---- | ---- | ---- | ---- | +| 138 | 21 | 76 | 75 | 161 | 162 | 175 | 163 | 174 | 鬼畜 -| 鬼畜调教 | 音MAD | 人力VOCALOID | 教程演示 | -| ---- | ---- | ---------- | ---- | -| 22 | 26 | 126 | 127 | +| 鬼畜调教 | 音 MAD | 人力 VOCALOID | 教程演示 | +| -------- | ------ | ------------- | -------- | +| 22 | 26 | 126 | 127 | s -| 美妆 | 服饰 | 健身 | 资讯 | +| 美妆 | 服饰 | 健身 | 资讯 | | ---- | ---- | ---- | ---- | | 157 | 158 | 164 | 159 | 广告 -| 广告 | +| 广告 | | ---- | | 166 | 娱乐 -| 综艺 | 明星 | Korea相关 | -| ---- | ---- | ------- | -| 71 | 137 | 131 | +| 综艺 | 明星 | Korea 相关 | +| ---- | ---- | ---------- | +| 71 | 137 | 131 | 影视 -| 影视杂谈 | 影视剪辑 | 短片 | 预告·资讯 | 特摄 | -| ---- | ---- | ---- | ----- | ---- | -| 182 | 183 | 85 | 184 | 86 | +| 影视杂谈 | 影视剪辑 | 短片 | 预告·资讯 | 特摄 | +| -------- | -------- | ---- | --------- | ---- | +| 182 | 183 | 85 | 184 | 86 | ### 视频评论 @@ -208,7 +210,9 @@ order: 排序方式,live_time 开播时间,online 人气 ### 直播分区 ::: warning 注意 + 由于接口未提供开播时间,如果直播间未更换标题与分区,将只会出现一次.如果直播间更换分区与标题,将再出现一次 + ::: 举例: [https://rsshub.app/bilibili/live/area/143/online](https://rsshub.app/bilibili/live/area/143/online) @@ -217,7 +221,7 @@ order: 排序方式,live_time 开播时间,online 人气 参数 -areaID: 分区ID 分区增删较多,可通过 [分区列表](https://api.live.bilibili.com/room/v1/Area/getList) 查询 +areaID: 分区 ID 分区增删较多,可通过 [分区列表](https://api.live.bilibili.com/room/v1/Area/getList) 查询 order: 排序方式,live_time 开播时间,online 人气 @@ -232,7 +236,9 @@ order: 排序方式,live_time 开播时间,online 人气 参数: uid,用户 id,博主主页打开控制台执行 `/uid=(\d+)/. exec(document.querySelector('.opt_box .btn_bed').getAttribute('action-data'))[1]` 获取 ::: warning 注意 + 上述方案获取 V+ 付费博主会有数据缺失,所以这里提供另外一种方式,这种方式的缺点是描述不如上面的完善,建议优先选择第一种方案 + ::: 举例: [https://rsshub.app/weibo/user2/3306934123](https://rsshub.app/weibo/user2/3306934123) @@ -270,7 +276,9 @@ order: 排序方式,live_time 开播时间,online 人气 ### 公众号 ::: tip 提示 + 公众号抓取困难,目前可提供的方案是通过即刻的公众号主题订阅 + ::: 举例: [https://rsshub.app/jike/topic/584b8ac671a288001154a115](https://rsshub.app/jike/topic/584b8ac671a288001154a115) @@ -311,9 +319,9 @@ order: 排序方式,live_time 开播时间,online 人气 参数: category,分类名 -| 前端 | Android | iOS | 后端 | 设计 | 产品 | 工具资源 | 阅读 | 人工智能 | -| -------- | ------- | ---- | ------- | ------ | ------- | ------- | ------- | ---- | -| frontend | android | ios | backend | design | product | freebie | article | ai | +| 前端 | Android | iOS | 后端 | 设计 | 产品 | 工具资源 | 阅读 | 人工智能 | +| -------- | ------- | --- | ------- | ------ | ------- | -------- | ------- | -------- | +| frontend | android | ios | backend | design | product | freebie | article | ai | ## 简书 @@ -357,7 +365,6 @@ order: 排序方式,live_time 开播时间,online 人气 参数: id,作者 id,可在作者主页 URL 中找到 - ## 知乎 ### 收藏夹 @@ -419,7 +426,9 @@ keyword: 关键词 ## 快递 ::: warning 注意 + 快递送达后请及时取消订阅,以免不必要地浪费服务器资源 + ::: 举例: [https://rsshub.app/express/youzhengguoji/CV054432809US](https://rsshub.app/express/youzhengguoji/CV054432809US) @@ -445,7 +454,9 @@ number: 快递单号 ## 妹子图 ::: warning 注意 + 该网站在国外无法访问,故以下演示无效 + ::: ### 首页(最新) @@ -462,10 +473,9 @@ number: 快递单号 参数:category,分类名 -| 热门 | 推荐 | 性感妹子 | 日本妹子 | 台湾妹子 | 清纯妹子 | -| ---- | ---- | ------- | ----- | ------ | ---- | -| hot | best | xinggan | japan | taiwan | mm | - +| 热门 | 推荐 | 性感妹子 | 日本妹子 | 台湾妹子 | 清纯妹子 | +| ---- | ---- | -------- | -------- | -------- | -------- | +| hot | best | xinggan | japan | taiwan | mm | ### 所有专题 @@ -517,13 +527,13 @@ number: 快递单号 mode: 排行榜类型 -| pixiv 日排行 | pixiv 周排行 | pixiv 月排行 | pixiv 受男性欢迎排行 | pixiv 受女性欢迎排行 | pixiv 原创作品排行 | pixiv 新人排行 | -| --------- | --------- | --------- | ------------- | ------------- | ------------- | ----------- | -| day | week | month | day_male | day_female | week_original | week_rookie | +| pixiv 日排行 | pixiv 周排行 | pixiv 月排行 | pixiv 受男性欢迎排行 | pixiv 受女性欢迎排行 | pixiv 原创作品排行 | pixiv 新人排行 | +| ------------ | ------------ | ------------ | -------------------- | -------------------- | ------------------ | -------------- | +| day | week | month | day_male | day_female | week_original | week_rookie | | pixiv R-18 日排行 | pixiv R-18 受男性欢迎排行 | pixiv R-18 受女性欢迎排行 | pixiv R-18 周排行 | pixiv R-18G 排行 | -| -------------- | ------------------ | ------------------ | -------------- | -------------- | -| day_r18 | day_male_r18 | day_female_r18 | week_r18 | week_r18g | +| ----------------- | ------------------------- | ------------------------- | ----------------- | ---------------- | +| day_r18 | day_male_r18 | day_female_r18 | week_r18 | week_r18g | date: 日期,取值形如 `2018-4-25` @@ -609,7 +619,7 @@ city: 城市的中文名,可选,默认北京 参数 -project: 产品ID +project: 产品 ID key: 产品密钥 diff --git a/docs/install/README.md b/docs/install/README.md index 1fc9cf7196151e..b93e5e83f3e1ec 100644 --- a/docs/install/README.md +++ b/docs/install/README.md @@ -4,13 +4,13 @@ sidebar: auto # 部署 -部署 RSSHub 非常简单,如果您在部署过程中遇到无法解决的问题请到 [issues](https://github.com/DIYgod/RSSHub/issues) 寻找类似的问题或 [向我们提问](https://github.com/DIYgod/RSSHub/issues/new),我们会尽快给您答复。 +部署 RSSHub 非常简单,如果您在部署过程中遇到无法解决的问题请到 [issues](https://github.com/DIYgod/RSSHub/issues) 寻找类似的问题或 [向我们提问](https://github.com/DIYgod/RSSHub/issues/new),我们会尽快给您答复。 [[toc]] ## 手动部署 -部署 `RSSHub` 最直接的方式,您可以按照以下步骤将 `RSSHub` 部署在您的电脑、服务器或者其他任何地方。 +部署 `RSSHub` 最直接的方式, 您可以按照以下步骤将 `RSSHub` 部署在您的  电脑、服务器或者其他任何地方。 ### 在安装之前 @@ -19,37 +19,42 @@ sidebar: auto ### 安装 Git ::: tip 提示 + 首先您应该输入 `git`,看看系统有没有安装 Git: windows 打开 `cmd`, macOS 打开`终端(terminal)`。 -``` bash +```bash $ git usage: git [--version] [--help] [-C ] [-c name=value] ... ``` + ::: -* Windows:从Git官网直接[下载安装程序](https://git-scm.com/downloads)。 -* MacOS:使用 [Homebrew](https://brew.sh/) `$ brew install git` 或者[下载安装程序](https://git-scm.com/download/mac)。 -* Linux:使用您的包管理器安装例如 `$ sudo apt-get install git`。 +* Windows:从 Git 官网直接[下载安装程序](https://git-scm.com/downloads)。 +* MacOS:使用 [Homebrew](https://brew.sh/) `$ brew install git` 或者[下载安装程序](https://git-scm.com/download/mac)。 +* Linux:使用您的包管理器安装例如 `$ sudo apt-get install git`。 ### 安装 Node.JS #### Windows + Windows 用户请 [下载安装程序](https://nodejs.org/zh-cn/)。安装时,请勾选`Add to PATH`选项。 #### MacOS & Linux + 安装 NodeJS 的最佳方式是使用 [nvm](https://github.com/creationix/nvm)。 安装 `nvm` -``` bash + +```bash $ curl https://raw.github.com/creationix/nvm/master/install.sh | sh ``` 安装完成后,重启终端并执行下列命令即可安装 `Node.js`。 -``` bash +```bash $ nvm install node ``` @@ -57,33 +62,36 @@ $ nvm install node 首先是下载 `RSSHub` 的源码,请执行下列命令。 -``` bash +```bash $ git clone https://github.com/DIYgod/RSSHub.git $ cd RSSHub ``` 下载完成后,需要安装依赖。 -``` bash +```bash $ npm install ``` ::: tip 提示 + 推荐使用 [Yarn](https://yarn.bootcss.com/) ,`Yarn` 比 `npm` 更快更稳定。 使用 `Yarn` 安装依赖时只需要键入 -``` bash + +```bash $ yarn ``` 由于众所周知的原因,在中国使用 `npm` 下载依赖十分缓慢,建议挂一个代理或者考虑使用 [NPM 镜像](https://npm.taobao.org/)。 + ::: ### 启动 RSSHub 在 `RSSHub` 文件夹中运行下面的命令就可以启动。 -``` bash +```bash $ npm start ``` @@ -110,7 +118,9 @@ macOS & Linux 运行 `$ PORT=1000` RSSHub 默认会有 5 分钟的缓存,默认这个缓存是存放在内存中的。RSSHub 还支持 Redis 数据库缓存。 ::: tip 提示 + 除非流量特别大或者您需要建立分布式集群,否则不需要 Redis 缓存。 + ::: #### 安装 Redis @@ -121,7 +131,7 @@ RSSHub 默认会有 5 分钟的缓存,默认这个缓存是存放在内存中 在安装目录中运行下面的命令启动 Redis。 -``` bash +```bash $ redis-server redis.windows.conf ``` @@ -129,13 +139,13 @@ $ redis-server redis.windows.conf 使用 [Homebrew](https://brew.sh/) 安装 Redis。 -``` bash +```bash $ brew install redis ``` 再运行下面的命令启动 Redis。 -``` bash +```bash $ brew services start redis ``` @@ -143,7 +153,7 @@ $ brew services start redis 使用您的包管理器安装 Redis。 -``` bash +```bash # apt $ sudo apt install redis-server @@ -169,13 +179,13 @@ Docker 属于 Linux 容器的一种封装,提供简单易用的容器使用接 运行下面的命令下载 RSSHub 镜像。 -``` bash +```bash $ docker pull diygod/rsshub ``` 然后运行 RSSHub 即可 -``` bash +```bash $ docker run -d --name rsshub -p 1200:1200 diygod/rsshub ``` @@ -183,7 +193,7 @@ $ docker run -d --name rsshub -p 1200:1200 diygod/rsshub 您可以使用下面的命令来关闭 RSSHub。 -``` bash +```bash $ docker stop rsshub ``` @@ -191,9 +201,9 @@ $ docker stop rsshub 配置运行在 docker 中的 RSSHub,最便利的方法是使用环境变量。 -以设置缓存时间为1小时举例,只需要在运行时增加参数:`-e CACHE_EXPIRE=3600` +以设置缓存时间为 1 小时举例,只需要在运行时增加参数:`-e CACHE_EXPIRE=3600` -``` bash +```bash $ docker run -d --name rsshub -p 1200:1200 -e CACHE_EXPIRE=3600 PORT=1000 diygod/rsshub ``` @@ -203,23 +213,23 @@ $ docker run -d --name rsshub -p 1200:1200 -e CACHE_EXPIRE=3600 PORT=1000 diygod [docker-compose](https://docs.docker.com/compose/overview/) 是用来运行多容器 Docker 应用的小工具,可以简化配置部署过程: -1. 创建 volume 持久化 Redis 缓存 +1. 创建 volume 持久化 Redis 缓存 -``` bash +```bash $ docker volume create redis-data ``` -2. 修改 [docker-compose.yml](https://github.com/DIYgod/RSSHub/blob/master/docker-compose.yml) 中的 `environment` 进行配置 +2. 修改 [docker-compose.yml](https://github.com/DIYgod/RSSHub/blob/master/docker-compose.yml) 中的 `environment` 进行配置 -3. 部署 +3. 部署 -``` bash +```bash $ docker-compose up ``` -4. 更新 +4. 更新 -``` bash +```bash $ docker-compose build $ docker-compose up ``` @@ -235,7 +245,9 @@ $ docker-compose up 可以通过修改 `config.js` 或者设置环境变量来配置 RSSHub。 ::: tip 提示 + 建议通过设置环境变量来配置 RSSHub。避免版本更新时的冲突。 + ::: `PORT`: 监听端口,默认为 `1200` diff --git a/docs/joinus/README.md b/docs/joinus/README.md index 09e1df0fbea0b6..c3752c02d67b29 100644 --- a/docs/joinus/README.md +++ b/docs/joinus/README.md @@ -8,12 +8,12 @@ sidebar: auto ## 提交新的 RSS 内容 -1. 在 [/router.js](https://github.com/DIYgod/RSSHub/blob/master/router.js) 里添加路由 +1. 在 [/router.js](https://github.com/DIYgod/RSSHub/blob/master/router.js) 里添加路由 -1. 在 [/routes/](https://github.com/DIYgod/RSSHub/tree/master/routes) 中的路由对应路径添加获取 RSS 内容的脚本 +1. 在 [/routes/](https://github.com/DIYgod/RSSHub/tree/master/routes) 中的路由对应路径添加获取 RSS 内容的脚本 -1. 更新 README 和文档: [/README.md](https://github.com/DIYgod/RSSHub/blob/master/README.md) [/docs/README.md](https://github.com/DIYgod/RSSHub/blob/master/docs/README.md) +1. 更新 README 和文档: [/README.md](https://github.com/DIYgod/RSSHub/blob/master/README.md) [/docs/README.md](https://github.com/DIYgod/RSSHub/blob/master/docs/README.md) ## 参与讨论 -1. [Telegram 群](https://t.me/rsshub) \ No newline at end of file +1. [Telegram 群](https://t.me/rsshub) diff --git a/docs/support/README.md b/docs/support/README.md index 9a4368a28893f8..dd53e4c935dbf9 100644 --- a/docs/support/README.md +++ b/docs/support/README.md @@ -12,24 +12,24 @@ RSSHub 是采用 MIT 许可的开源项目,使用完全免费。 但是随着 我们通过以下方式接受赞助: -- [微信支付](https://i.imgur.com/aq6PtWa.png) -- [支付宝](https://i.imgur.com/wv1Pj2k.png) -- [Paypal](https://www.paypal.me/DIYgod) -- 比特币: 13CwQLHzPYm2tewNMSJBeArbbRM5NSmCD1 +* [微信支付](https://i.imgur.com/aq6PtWa.png) +* [支付宝](https://i.imgur.com/wv1Pj2k.png) +* [Paypal](https://www.paypal.me/DIYgod) +* 比特币: 13CwQLHzPYm2tewNMSJBeArbbRM5NSmCD1 ## 周期性赞助 周期性赞助可以获得额外的回报,比如你的名字 会出现在 RSSHub 的 GitHub 仓库和现在我们的官网中。 -- 通过 [OpenCollective](https://opencollective.com/RSSHub) 赞助成为 backer 或 sponsor -- 通过 [Patreon](https://www.patreon.com/DIYgod) 赞助成为 backer -- 给我们发邮件联系赞助事宜: i#html.love +* 通过 [OpenCollective](https://opencollective.com/RSSHub) 赞助成为 backer 或 sponsor +* 通过 [Patreon](https://www.patreon.com/DIYgod) 赞助成为 backer +* 给我们发邮件联系赞助事宜: i#html.love ## 鸣谢 ### Sponsors -- [Sayori Studio](https://t.me/SayoriStudio) +* [Sayori Studio](https://t.me/SayoriStudio) ### Contributors diff --git a/index.js b/index.js index 777d1187e6a61a..3d6f8ab604472f 100644 --- a/index.js +++ b/index.js @@ -59,7 +59,7 @@ if (config.cacheType === 'memory') { }, onconnect: () => { logger.info('Redis connect.'); - } + }, }) ); } diff --git a/middleware/filter.js b/middleware/filter.js index 27262094561164..ab51157afdefb4 100644 --- a/middleware/filter.js +++ b/middleware/filter.js @@ -5,9 +5,11 @@ module.exports = async (ctx, next) => { ctx.state.data.item = ctx.state.data.item.filter((item) => { const title = item.title; const description = item.description; - return !(ctx.query.filter && !title.match(ctx.query.filter) && !description.match(ctx.query.filter) - || ctx.query.filter_title && !title.match(ctx.query.filter_title) - || ctx.query.filter_description && !description.match(ctx.query.filter_description)); + return !( + (ctx.query.filter && !title.match(ctx.query.filter) && !description.match(ctx.query.filter)) || + (ctx.query.filter_title && !title.match(ctx.query.filter_title)) || + (ctx.query.filter_description && !description.match(ctx.query.filter_description)) + ); }); } }; diff --git a/middleware/header.js b/middleware/header.js index 689a13ae51c77b..33de6f3e524be5 100644 --- a/middleware/header.js +++ b/middleware/header.js @@ -11,4 +11,4 @@ module.exports = async (ctx, next) => { }; ctx.set(headers); await next(); -}; \ No newline at end of file +}; diff --git a/middleware/lru-cache.js b/middleware/lru-cache.js index b2c9aad3dfd500..ead097f7891496 100644 --- a/middleware/lru-cache.js +++ b/middleware/lru-cache.js @@ -5,7 +5,7 @@ const readall = require('readall'); const crypto = require('crypto'); const lru = require('lru-cache'); -module.exports = function (options = {}) { +module.exports = function(options = {}) { const { prefix = 'koa-cache:', expire = 30 * 60, // 30 min @@ -18,10 +18,10 @@ module.exports = function (options = {}) { const memoryCache = lru({ maxAge: expire * 1000, - max: maxLength + max: maxLength, }); - return async function cache (ctx, next) { + return async function cache(ctx, next) { const { url, path } = ctx.request; const resolvedPrefix = typeof prefix === 'function' ? prefix.call(ctx, ctx) : prefix; const key = resolvedPrefix + md5(ignoreQuery ? path : url); @@ -50,7 +50,7 @@ module.exports = function (options = {}) { } } - if (!match || passParam && ctx.request.query[passParam]) { + if (!match || (passParam && ctx.request.query[passParam])) { return await next(); } @@ -69,14 +69,14 @@ module.exports = function (options = {}) { try { const trueExpire = routeExpire || expire; await setCache(ctx, key, tkey, trueExpire); - } catch (e) { } + } catch (e) {} // eslint-disable-line no-empty routeExpire = false; }; /** * getCache */ - async function getCache (ctx, key, tkey) { + async function getCache(ctx, key, tkey) { const value = memoryCache.get(key); let type; let ok = false; @@ -85,7 +85,9 @@ module.exports = function (options = {}) { ctx.response.status = 200; type = memoryCache.get(tkey) || 'text/html'; // can happen if user specified return_buffers: true in redis options - if (Buffer.isBuffer(type)) {type = type.toString();} + if (Buffer.isBuffer(type)) { + type = type.toString(); + } ctx.response.set('X-Koa-Memory-Cache', 'true'); ctx.response.type = type; try { @@ -102,7 +104,7 @@ module.exports = function (options = {}) { /** * setCache */ - async function setCache (ctx, key, tkey) { + async function setCache(ctx, key, tkey) { ctx.state.data.lastBuildDate = new Date().toUTCString(); const body = JSON.stringify(ctx.state.data); @@ -120,7 +122,7 @@ module.exports = function (options = {}) { /** * cacheType */ - async function cacheType (ctx, tkey) { + async function cacheType(ctx, tkey) { const type = ctx.response.type; if (type) { memoryCache.set(tkey, type); @@ -128,7 +130,7 @@ module.exports = function (options = {}) { } }; -function paired (route, path) { +function paired(route, path) { const options = { sensitive: true, strict: true, @@ -137,7 +139,8 @@ function paired (route, path) { return pathToRegExp(route, [], options).exec(path); } -function read (stream) { +// eslint-disable-next-line no-unused-vars +function read(stream) { return new Promise((resolve, reject) => { readall(stream, (err, data) => { if (err) { @@ -149,6 +152,9 @@ function read (stream) { }); } -function md5 (str) { - return crypto.createHash('md5').update(str).digest('hex'); -} \ No newline at end of file +function md5(str) { + return crypto + .createHash('md5') + .update(str) + .digest('hex'); +} diff --git a/middleware/onerror.js b/middleware/onerror.js index 75bc9c40866aca..ff6ac21f280191 100644 --- a/middleware/onerror.js +++ b/middleware/onerror.js @@ -11,4 +11,4 @@ module.exports = async (ctx, next) => { ctx.body = 'RSSHub 发生了一些意外: ' + err; ctx.status = 500; } -}; \ No newline at end of file +}; diff --git a/middleware/redis-cache.js b/middleware/redis-cache.js index 74e2ff9ba9f8ca..72c7ad11c8560c 100644 --- a/middleware/redis-cache.js +++ b/middleware/redis-cache.js @@ -6,7 +6,7 @@ const readall = require('readall'); const crypto = require('crypto'); const Redis = require('redis'); -module.exports = function (options = {}) { +module.exports = function(options = {}) { let redisAvailable = false; const { @@ -17,20 +17,15 @@ module.exports = function (options = {}) { passParam = '', maxLength = Infinity, ignoreQuery = false, - onerror = function () { }, - onconnect = function () {}, + onerror = function() {}, + onconnect = function() {}, } = options; - const { - host:redisHost = 'localhost', - port:redisPort = 6379, - url:redisUrl = `redis://${redisHost}:${redisPort}/`, - options:redisOptions = {} - } = options.redis || {}; + const { host: redisHost = 'localhost', port: redisPort = 6379, url: redisUrl = `redis://${redisHost}:${redisPort}/`, options: redisOptions = {} } = options.redis || {}; /** - * redisClient - */ + * redisClient + */ const redisClient = wrapper(Redis.createClient(redisUrl, redisOptions)); redisClient.on('error', (error) => { redisAvailable = false; @@ -44,7 +39,7 @@ module.exports = function (options = {}) { onconnect(); }); - return async function cache (ctx, next) { + return async function cache(ctx, next) { const { url, path } = ctx.request; const resolvedPrefix = typeof prefix === 'function' ? prefix.call(ctx, ctx) : prefix; const key = resolvedPrefix + md5(ignoreQuery ? path : url); @@ -73,7 +68,7 @@ module.exports = function (options = {}) { } } - if (!redisAvailable || !match || passParam && ctx.request.query[passParam]) { + if (!redisAvailable || !match || (passParam && ctx.request.query[passParam])) { return await next(); } @@ -92,23 +87,25 @@ module.exports = function (options = {}) { try { const trueExpire = routeExpire || expire; await setCache(ctx, key, tkey, trueExpire); - } catch (e) { } + } catch (e) {} // eslint-disable-line no-empty routeExpire = false; }; /** - * getCache - */ - async function getCache (ctx, key, tkey) { + * getCache + */ + async function getCache(ctx, key, tkey) { const value = await redisClient.get(key); let type; let ok = false; if (value) { ctx.response.status = 200; - type = await redisClient.get(tkey) || 'text/html'; + type = (await redisClient.get(tkey)) || 'text/html'; // can happen if user specified return_buffers: true in redis options - if (Buffer.isBuffer(type)) {type = type.toString();} + if (Buffer.isBuffer(type)) { + type = type.toString(); + } ctx.response.set('X-Koa-Redis-Cache', 'true'); ctx.response.type = type; try { @@ -123,9 +120,9 @@ module.exports = function (options = {}) { } /** - * setCache - */ - async function setCache (ctx, key, tkey, expire) { + * setCache + */ + async function setCache(ctx, key, tkey, expire) { ctx.state.data.lastBuildDate = new Date().toUTCString(); const body = JSON.stringify(ctx.state.data); @@ -141,9 +138,9 @@ module.exports = function (options = {}) { } /** - * cacheType - */ - async function cacheType (ctx, tkey, expire) { + * cacheType + */ + async function cacheType(ctx, tkey, expire) { const type = ctx.response.type; if (type) { await redisClient.setex(tkey, expire, type); @@ -151,7 +148,7 @@ module.exports = function (options = {}) { } }; -function paired (route, path) { +function paired(route, path) { const options = { sensitive: true, strict: true, @@ -160,7 +157,8 @@ function paired (route, path) { return pathToRegExp(route, [], options).exec(path); } -function read (stream) { +// eslint-disable-next-line no-unused-vars +function read(stream) { return new Promise((resolve, reject) => { readall(stream, (err, data) => { if (err) { @@ -172,6 +170,9 @@ function read (stream) { }); } -function md5 (str) { - return crypto.createHash('md5').update(str).digest('hex'); +function md5(str) { + return crypto + .createHash('md5') + .update(str) + .digest('hex'); } diff --git a/middleware/template.js b/middleware/template.js index 8cb2727393b425..2d822912fc2e1c 100644 --- a/middleware/template.js +++ b/middleware/template.js @@ -11,4 +11,4 @@ module.exports = async (ctx, next) => { ...ctx.state.data, }); } -}; \ No newline at end of file +}; diff --git a/middleware/utf8.js b/middleware/utf8.js index c513eb2da739a8..4c90349d0440ab 100644 --- a/middleware/utf8.js +++ b/middleware/utf8.js @@ -2,5 +2,5 @@ // https://stackoverflow.com/questions/1497885/remove-control-characters-from-php-string/1497928#1497928 module.exports = async (ctx, next) => { await next(); - ctx.body = ctx.body?ctx.body.replace(/[\x00-\x1F\x7F]/g, ''):ctx.body; + ctx.body = ctx.body ? ctx.body.replace(/[\x00-\x1F\x7F]/g, '') : ctx.body; }; diff --git a/package.json b/package.json index cafa308f4bbc03..e832300b249232 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,26 @@ { - "name": "RSSHub", + "name": "rsshub", "version": "0.0.1", "description": "Make RSS Great Again!", "main": "index.js", "scripts": { "start": "node index.js", "docs:dev": "vuepress dev docs", - "docs:build": "vuepress build docs" + "docs:build": "vuepress build docs", + "format": "prettier \"**/*.{js,json,md}\" --write" + }, + "gitHooks": { + "pre-commit": "lint-staged" + }, + "lint-staged": { + "*.js": [ + "eslint --fix", + "git add" + ], + "*.{js,json,md}": [ + "prettier --write", + "git add" + ] }, "repository": { "type": "git", @@ -22,7 +36,13 @@ }, "homepage": "https://github.com/DIYgod/RSSHub#readme", "devDependencies": { - "vuepress": "0.8.4" + "eslint": "4.19.1", + "eslint-config-prettier": "^2.9.0", + "eslint-plugin-prettier": "^2.6.0", + "lint-staged": "^7.1.0", + "prettier": "^1.12.1", + "vuepress": "0.8.4", + "yorkie": "^1.0.3" }, "dependencies": { "art-template": "4.12.2", @@ -30,7 +50,6 @@ "cheerio": "1.0.0-rc.2", "co-redis": "2.1.1", "crypto": "1.0.1", - "eslint": "4.19.1", "form-data": "^2.3.2", "googleapis": "30.0.0", "json-bigint": "0.2.3", diff --git a/process.json b/process.json index 2b6678bb5a7f8f..1561a3323252fe 100644 --- a/process.json +++ b/process.json @@ -1,11 +1,13 @@ { - "apps": [{ - "name": "rsshub", - "script": "index.js", - "instances": "max", - "exec_mode": "cluster", - "env": { - "NODE_ENV": "production" + "apps": [ + { + "name": "rsshub", + "script": "index.js", + "instances": "max", + "exec_mode": "cluster", + "env": { + "NODE_ENV": "production" + } } - }] -} \ No newline at end of file + ] +} diff --git a/router.js b/router.js index 69b8f0533f2718..12a12e49d2d7a1 100644 --- a/router.js +++ b/router.js @@ -58,7 +58,7 @@ router.get('/zhihu/collection/:id', require('./routes/zhihu/collection')); router.get('/zhihu/people/activities/:id', require('./routes/zhihu/activities')); router.get('/zhihu/people/answers/:id', require('./routes/zhihu/answers')); router.get('/zhihu/zhuanlan/:id', require('./routes/zhihu/zhuanlan')); -router.get('/zhihu/daily', require('./routes/zhihu/daily')) +router.get('/zhihu/daily', require('./routes/zhihu/daily')); // 贴吧 router.get('/tieba/forum/:kw', require('./routes/tieba/forum')); diff --git a/routes/bilibili/bangumi.js b/routes/bilibili/bangumi.js index 3885a88521875c..68f01f9d407b7c 100644 --- a/routes/bilibili/bangumi.js +++ b/routes/bilibili/bangumi.js @@ -9,8 +9,8 @@ module.exports = async (ctx) => { url: `https://bangumi.bilibili.com/jsonp/seasoninfo/${seasonid}.ver?callback=seasonListCallback&jsonp=jsonp&_=${+new Date()}`, headers: { 'User-Agent': config.ua, - 'Referer': `https://bangumi.bilibili.com/anime/${seasonid}/` - } + Referer: `https://bangumi.bilibili.com/anime/${seasonid}/`, + }, }); const data = JSON.parse(response.data.match(/^seasonListCallback\((.*)\);$/)[1]).result || {}; @@ -19,11 +19,13 @@ module.exports = async (ctx) => { title: data.title, link: `https://bangumi.bilibili.com/anime/${seasonid}/`, description: data.evaluate, - item: data.episodes && data.episodes.map((item) => ({ - title: `第${item.index}话 ${item.index_title}`, - description: `更新时间:${item.update_time}`, - pubDate: new Date(item.update_time).toUTCString(), - link: item.webplay_url - })), + item: + data.episodes && + data.episodes.map((item) => ({ + title: `第${item.index}话 ${item.index_title}`, + description: `更新时间:${item.update_time}`, + pubDate: new Date(item.update_time).toUTCString(), + link: item.webplay_url, + })), }; -}; \ No newline at end of file +}; diff --git a/routes/bilibili/coin.js b/routes/bilibili/coin.js index a7a230834d3acf..f242658412942a 100644 --- a/routes/bilibili/coin.js +++ b/routes/bilibili/coin.js @@ -10,11 +10,11 @@ module.exports = async (ctx) => { url: 'https://space.bilibili.com/ajax/member/GetInfo', headers: { 'User-Agent': config.ua, - 'Referer': `https://space.bilibili.com/${uid}/`, + Referer: `https://space.bilibili.com/${uid}/`, 'Content-Type': 'application/x-www-form-urlencoded', }, data: qs.stringify({ - mid: uid + mid: uid, }), }); const name = nameResponse.data.data.name; @@ -24,8 +24,8 @@ module.exports = async (ctx) => { url: `https://space.bilibili.com/ajax/member/getCoinVideos?mid=${uid}`, headers: { 'User-Agent': config.ua, - 'Referer': `https://space.bilibili.com/${uid}/` - } + Referer: `https://space.bilibili.com/${uid}/`, + }, }); const data = response.data; @@ -33,10 +33,13 @@ module.exports = async (ctx) => { title: `${name} 的 bilibili 投币视频`, link: `https://space.bilibili.com/${uid}`, description: `${name} 的 bilibili 投币视频`, - item: data.data && data.data.list && data.data.list.map((item) => ({ - title: item.title, - description: `${item.title}
`, - link: `https://www.bilibili.com/video/av${item.stat.aid}` - })), + item: + data.data && + data.data.list && + data.data.list.map((item) => ({ + title: item.title, + description: `${item.title}
`, + link: `https://www.bilibili.com/video/av${item.stat.aid}`, + })), }; -}; \ No newline at end of file +}; diff --git a/routes/bilibili/dynamic.js b/routes/bilibili/dynamic.js index d5694488e48093..a3bd2ec58d0ffa 100644 --- a/routes/bilibili/dynamic.js +++ b/routes/bilibili/dynamic.js @@ -10,8 +10,8 @@ module.exports = async (ctx) => { url: `https://api.vc.bilibili.com/dynamic_svr/v1/dynamic_svr/space_history?host_uid=${uid}`, headers: { 'User-Agent': config.ua, - 'Referer': `https://space.bilibili.com/${uid}/` - } + Referer: `https://space.bilibili.com/${uid}/`, + }, }); const data = response.data.data.cards; @@ -38,11 +38,9 @@ module.exports = async (ctx) => { let link = ''; if (data.dynamic_id) { link = `https://t.bilibili.com/${data.dynamic_id}`; - } - else if (data.aid) { + } else if (data.aid) { link = `https://www.bilibili.com/video/av${data.aid}`; - } - else if (data.id) { + } else if (data.id) { link = `https://h.bilibili.com/${data.id}`; } @@ -50,8 +48,8 @@ module.exports = async (ctx) => { title: data.title || data.description || data.content, description: `${data.desc || data.description || data.content}${imgHTML}`, pubDate: new Date((data.pubdate || data.upload_time || data.timestamp) * 1000).toUTCString(), - link: link + link: link, }; }), }; -}; \ No newline at end of file +}; diff --git a/routes/bilibili/fav.js b/routes/bilibili/fav.js index 2e93f0ffce07f5..776e0f03c6b2e9 100644 --- a/routes/bilibili/fav.js +++ b/routes/bilibili/fav.js @@ -10,11 +10,11 @@ module.exports = async (ctx) => { url: 'https://space.bilibili.com/ajax/member/GetInfo', headers: { 'User-Agent': config.ua, - 'Referer': `https://space.bilibili.com/${uid}/`, + Referer: `https://space.bilibili.com/${uid}/`, 'Content-Type': 'application/x-www-form-urlencoded', }, data: qs.stringify({ - mid: uid + mid: uid, }), }); const name = nameResponse.data.data.name; @@ -24,8 +24,8 @@ module.exports = async (ctx) => { url: `https://api.bilibili.com/x/v2/fav/video?vmid=${uid}&ps=30&tid=0&keyword=&pn=1&order=fav_time`, headers: { 'User-Agent': config.ua, - 'Referer': `https://space.bilibili.com/${uid}/#/favlist` - } + Referer: `https://space.bilibili.com/${uid}/#/favlist`, + }, }); const data = response.data; @@ -33,12 +33,15 @@ module.exports = async (ctx) => { title: `${name} 的 bilibili 收藏夹`, link: `https://space.bilibili.com/${uid}/#/favlist`, description: `${name} 的 bilibili 收藏夹`, - - item: data.data && data.data.archives && data.data.archives.map((item) => ({ - title: item.title, - description: `${item.desc}
`, - pubDate: new Date(item.fav_at * 1000).toUTCString(), - link: `https://www.bilibili.com/video/av${item.aid}` - })), + + item: + data.data && + data.data.archives && + data.data.archives.map((item) => ({ + title: item.title, + description: `${item.desc}
`, + pubDate: new Date(item.fav_at * 1000).toUTCString(), + link: `https://www.bilibili.com/video/av${item.aid}`, + })), }; -}; \ No newline at end of file +}; diff --git a/routes/bilibili/followers.js b/routes/bilibili/followers.js index b4bc6734cbdb76..532c7233b7b43d 100644 --- a/routes/bilibili/followers.js +++ b/routes/bilibili/followers.js @@ -10,11 +10,11 @@ module.exports = async (ctx) => { url: 'https://space.bilibili.com/ajax/member/GetInfo', headers: { 'User-Agent': config.ua, - 'Referer': `https://space.bilibili.com/${uid}/`, + Referer: `https://space.bilibili.com/${uid}/`, 'Content-Type': 'application/x-www-form-urlencoded', }, data: qs.stringify({ - mid: uid + mid: uid, }), }); const name = nameResponse.data.data.name; @@ -24,8 +24,8 @@ module.exports = async (ctx) => { url: `https://api.bilibili.com/x/relation/stat?vmid=${uid}`, headers: { 'User-Agent': config.ua, - 'Referer': `https://space.bilibili.com/${uid}/`, - } + Referer: `https://space.bilibili.com/${uid}/`, + }, }); const count = countResponse.data.data.follower; @@ -34,8 +34,8 @@ module.exports = async (ctx) => { url: `https://api.bilibili.com/x/relation/followers?vmid=${uid}`, headers: { 'User-Agent': config.ua, - 'Referer': `https://space.bilibili.com/${uid}/`, - } + Referer: `https://space.bilibili.com/${uid}/`, + }, }); const data = response.data.data.list; @@ -47,7 +47,7 @@ module.exports = async (ctx) => { title: `${name} 新粉丝 ${item.uname}`, description: `${item.uname}
${item.sign}
总计${count}`, pubDate: new Date(item.mtime * 1000).toUTCString(), - link: `https://space.bilibili.com/${item.mid}` + link: `https://space.bilibili.com/${item.mid}`, })), }; -}; \ No newline at end of file +}; diff --git a/routes/bilibili/followings.js b/routes/bilibili/followings.js index c8990d245b8cde..0a9dba627659ed 100644 --- a/routes/bilibili/followings.js +++ b/routes/bilibili/followings.js @@ -10,11 +10,11 @@ module.exports = async (ctx) => { url: 'https://space.bilibili.com/ajax/member/GetInfo', headers: { 'User-Agent': config.ua, - 'Referer': `https://space.bilibili.com/${uid}/`, + Referer: `https://space.bilibili.com/${uid}/`, 'Content-Type': 'application/x-www-form-urlencoded', }, data: qs.stringify({ - mid: uid + mid: uid, }), }); const name = nameResponse.data.data.name; @@ -24,8 +24,8 @@ module.exports = async (ctx) => { url: `https://api.bilibili.com/x/relation/stat?vmid=${uid}`, headers: { 'User-Agent': config.ua, - 'Referer': `https://space.bilibili.com/${uid}/`, - } + Referer: `https://space.bilibili.com/${uid}/`, + }, }); const count = countResponse.data.data.following; @@ -34,8 +34,8 @@ module.exports = async (ctx) => { url: `https://api.bilibili.com/x/relation/followings?vmid=${uid}`, headers: { 'User-Agent': config.ua, - 'Referer': `https://space.bilibili.com/${uid}/`, - } + Referer: `https://space.bilibili.com/${uid}/`, + }, }); const data = response.data.data.list; @@ -47,7 +47,7 @@ module.exports = async (ctx) => { title: `${name} 新关注 ${item.uname}`, description: `${item.uname}
${item.sign}
总计${count}`, pubDate: new Date(item.mtime * 1000).toUTCString(), - link: `https://space.bilibili.com/${item.mid}` + link: `https://space.bilibili.com/${item.mid}`, })), }; -}; \ No newline at end of file +}; diff --git a/routes/bilibili/linkNews.js b/routes/bilibili/linkNews.js index de9b5ad65d0339..58938755d984c4 100644 --- a/routes/bilibili/linkNews.js +++ b/routes/bilibili/linkNews.js @@ -4,19 +4,18 @@ const config = require('../../config'); module.exports = async (ctx) => { const product = ctx.params.product; - let productTitle = ``; + let productTitle = ''; switch (product) { - case "live": - productTitle = `直播`; + case 'live': + productTitle = '直播'; break; - case "vc": - productTitle = `小视频`; + case 'vc': + productTitle = '小视频'; break; - case "wh": - productTitle = `相簿`; + case 'wh': + productTitle = '相簿'; break; - } const response = await axios({ @@ -24,8 +23,8 @@ module.exports = async (ctx) => { url: `https://api.vc.bilibili.com/news/v1/notice/list?platform=pc&product=${product}&category=all&page_no=1&page_size=20`, headers: { 'User-Agent': config.ua, - 'Referer': `https://link.bilibili.com/p/eden/news` - } + Referer: 'https://link.bilibili.com/p/eden/news', + }, }); const data = response.data.data.items; @@ -34,11 +33,13 @@ module.exports = async (ctx) => { link: `https://link.bilibili.com/p/eden/news#/?tab=${product}&tag=all&page_no=1`, description: `bilibili ${productTitle}公告`, lastBuildDate: new Date().toUTCString(), - item: data && data.map((item) => ({ - title: item.title, - description: `${item.mark}
`, - pubDate: new Date(item.ctime.replace(' ', 'T') + "+08:00").toUTCString(), - link: item.announce_link ? item.announce_link : `https://link.bilibili.com/p/eden/news#/newsdetail?id=${item.id}` - })), + item: + data && + data.map((item) => ({ + title: item.title, + description: `${item.mark}
`, + pubDate: new Date(item.ctime.replace(' ', 'T') + '+08:00').toUTCString(), + link: item.announce_link ? item.announce_link : `https://link.bilibili.com/p/eden/news#/newsdetail?id=${item.id}`, + })), }; -}; \ No newline at end of file +}; diff --git a/routes/bilibili/liveArea.js b/routes/bilibili/liveArea.js index 759172c44a5dbb..d5345ad553e958 100644 --- a/routes/bilibili/liveArea.js +++ b/routes/bilibili/liveArea.js @@ -5,38 +5,37 @@ module.exports = async (ctx) => { const areaID = ctx.params.areaID; const order = ctx.params.order; - let orderTitle = ``; + let orderTitle = ''; switch (order) { - case "live_time": - orderTitle = `最新开播`; + case 'live_time': + orderTitle = '最新开播'; break; - case "online": - orderTitle = `人气直播`; + case 'online': + orderTitle = '人气直播'; break; } const nameResponse = await axios({ method: 'get', - url: `https://api.live.bilibili.com/room/v1/Area/getList`, + url: 'https://api.live.bilibili.com/room/v1/Area/getList', headers: { 'User-Agent': config.ua, - 'Referer': `https://link.bilibili.com/p/center/index` - } + Referer: 'https://link.bilibili.com/p/center/index', + }, }); - let parentTitle = ""; - let parentID = ""; - let areaTitle = ""; - let areaLink = ""; - + let parentTitle = ''; + let parentID = ''; + let areaTitle = ''; + let areaLink = ''; - for (parentArea of nameResponse.data.data) { - for (area of parentArea.list) { + for (const parentArea of nameResponse.data.data) { + for (const area of parentArea.list) { if (area.id === areaID) { parentTitle = parentArea.name; parentID = parentArea.id; areaTitle = area.name; - cateID = area.cate_id; + // cateID = area.cate_id; switch (parentID) { case 1: areaLink = `https://live.bilibili.com/pages/area/ent-all#${area.cate_id}/${areaID}`; @@ -46,7 +45,7 @@ module.exports = async (ctx) => { areaLink = `https://live.bilibili.com/p/eden/area-tags#/${parentID}/${areaID}`; break; case 4: - areaLink = "https://live.bilibili.com/pages/area/draw"; + areaLink = 'https://live.bilibili.com/pages/area/draw'; break; } } @@ -58,8 +57,8 @@ module.exports = async (ctx) => { url: `https://api.live.bilibili.com/room/v1/area/getRoomList?area_id=${areaID}&sort_type=${order}&page_size=30&page_no=1`, headers: { 'User-Agent': config.ua, - 'Referer': `https://live.bilibili.com/p/eden/area-tags` - } + Referer: 'https://live.bilibili.com/p/eden/area-tags', + }, }); const data = response.data.data; @@ -73,7 +72,7 @@ module.exports = async (ctx) => { description: `${item.uname} ${item.title}`, pubDate: new Date().toUTCString(), guid: `https://live.bilibili.com/${item.roomid} ${item.title}`, - link: `https://live.bilibili.com/${item.roomid}` + link: `https://live.bilibili.com/${item.roomid}`, })), }; -}; \ No newline at end of file +}; diff --git a/routes/bilibili/liveRoom.js b/routes/bilibili/liveRoom.js index 9b5a0c3373b377..5496c3bcf3af3e 100644 --- a/routes/bilibili/liveRoom.js +++ b/routes/bilibili/liveRoom.js @@ -4,16 +4,15 @@ const config = require('../../config'); module.exports = async (ctx) => { let roomID = ctx.params.roomID; - //短号查询长号 + // 短号查询长号 if (parseInt(roomID, 10) < 10000) { - const roomIDResponse = await axios({ method: 'get', url: `https://api.live.bilibili.com/room/v1/Room/room_init?id=${roomID}`, headers: { 'User-Agent': config.ua, - 'Referer': `https://live.bilibili.com/${roomID}` - } + Referer: `https://live.bilibili.com/${roomID}`, + }, }); roomID = roomIDResponse.data.data.room_id; } @@ -23,8 +22,8 @@ module.exports = async (ctx) => { url: `https://api.live.bilibili.com/live_user/v1/UserInfo/get_anchor_in_room?roomid=${roomID}`, headers: { 'User-Agent': config.ua, - 'Referer': `https://live.bilibili.com/${roomID}` - } + Referer: `https://live.bilibili.com/${roomID}`, + }, }); const name = nameResponse.data.data.info.uname; @@ -34,20 +33,20 @@ module.exports = async (ctx) => { url: `https://api.live.bilibili.com/room/v1/Room/get_info?room_id=${roomID}&from=room`, headers: { 'User-Agent': config.ua, - 'Referer': `https://live.bilibili.com/${roomID}` - } + Referer: `https://live.bilibili.com/${roomID}`, + }, }); const data = response.data.data; - let liveItem = []; + const liveItem = []; if (data.live_status === 1) { liveItem.push({ title: `${data.title} ${data.live_time}`, - description: `${ data.title}
${data.description}`, - pubDate: new Date(data.live_time.replace(' ', 'T') + "+08:00").toUTCString(), + description: `${data.title}
${data.description}`, + pubDate: new Date(data.live_time.replace(' ', 'T') + '+08:00').toUTCString(), guid: `https://live.bilibili.com/${roomID} ${data.live_time}`, - link: `https://live.bilibili.com/${roomID}` + link: `https://live.bilibili.com/${roomID}`, }); } @@ -58,4 +57,4 @@ module.exports = async (ctx) => { lastBuildDate: new Date().toUTCString(), item: liveItem, }; -}; \ No newline at end of file +}; diff --git a/routes/bilibili/liveSearch.js b/routes/bilibili/liveSearch.js index 8dc6bfc66a8fe7..68fa1e6b823188 100644 --- a/routes/bilibili/liveSearch.js +++ b/routes/bilibili/liveSearch.js @@ -1,6 +1,4 @@ const axios = require('axios'); -const art = require('art-template'); -const path = require('path'); const config = require('../../config'); module.exports = async (ctx) => { @@ -8,14 +6,14 @@ module.exports = async (ctx) => { const order = ctx.params.order; const urlEncodedKey = encodeURIComponent(key); - let orderTitle = ``; + let orderTitle = ''; switch (order) { - case "live_time": - orderTitle = `最新开播`; + case 'live_time': + orderTitle = '最新开播'; break; - case "online": - orderTitle = `人气直播`; + case 'online': + orderTitle = '人气直播'; break; } @@ -24,8 +22,8 @@ module.exports = async (ctx) => { url: `https://search.bilibili.com/api/search?search_type=live_room&keyword=${urlEncodedKey}&order=${order}&coverType=user_cover&page=1`, headers: { 'User-Agent': config.ua, - 'Referer': `https://search.bilibili.com/live?keyword=${urlEncodedKey}&order=${order}&coverType=user_cover&page=1&search_type=live` - } + Referer: `https://search.bilibili.com/live?keyword=${urlEncodedKey}&order=${order}&coverType=user_cover&page=1&search_type=live`, + }, }); const data = response.data.result; @@ -37,9 +35,9 @@ module.exports = async (ctx) => { item: data.map((item) => ({ title: `${item.uname} ${item.title} (${item.cate_name}-${item.live_time})`, description: `${item.uname} ${item.title} (${item.cate_name}-${item.live_time})`, - pubDate: new Date(item.live_time.replace(' ', 'T') + "+08:00").toUTCString(), + pubDate: new Date(item.live_time.replace(' ', 'T') + '+08:00').toUTCString(), guid: `https://live.bilibili.com/${item.roomid} ${item.live_time}`, - link: `https://live.bilibili.com/${item.roomid}` + link: `https://live.bilibili.com/${item.roomid}`, })), }; -}; \ No newline at end of file +}; diff --git a/routes/bilibili/partion.js b/routes/bilibili/partion.js index f11828f3c52d03..a4e5ed3595fa0a 100644 --- a/routes/bilibili/partion.js +++ b/routes/bilibili/partion.js @@ -9,8 +9,8 @@ module.exports = async (ctx) => { url: `https://api.bilibili.com/x/web-interface/newlist?ps=15&rid=${tid}&_=${+new Date()}`, headers: { 'User-Agent': config.ua, - 'Referer': 'https://www.bilibili.com/' - } + Referer: 'https://www.bilibili.com/', + }, }); const list = response.data.data.archives; @@ -23,11 +23,13 @@ module.exports = async (ctx) => { title: `bilibili ${name}分区`, link: 'https://www.bilibili.com', description: `bilibili ${name}分区`, - item: list && list.map((item) => ({ - title: `${item.title} - ${item.owner.name}`, - description: `${item.desc}`, - pubDate: new Date(item.pubdate * 1000).toUTCString(), - link: `https://www.bilibili.com/video/av${item.aid}` - })), + item: + list && + list.map((item) => ({ + title: `${item.title} - ${item.owner.name}`, + description: `${item.desc}`, + pubDate: new Date(item.pubdate * 1000).toUTCString(), + link: `https://www.bilibili.com/video/av${item.aid}`, + })), }; -}; \ No newline at end of file +}; diff --git a/routes/bilibili/reply.js b/routes/bilibili/reply.js index bfc5457c347521..ad0fa50068c210 100644 --- a/routes/bilibili/reply.js +++ b/routes/bilibili/reply.js @@ -12,20 +12,20 @@ module.exports = async (ctx) => { headers: { 'User-Agent': config.ua, }, - responseType: 'arraybuffer' + responseType: 'arraybuffer', }); const responseHtml = iconv.decode(nameResponse.data, 'UTF-8'); const $ = cheerio.load(responseHtml); - let name = $("title").text(); - name = name.substr(0, name.indexOf("_哔哩哔哩")); + let name = $('title').text(); + name = name.substr(0, name.indexOf('_哔哩哔哩')); const response = await axios({ method: 'get', url: `https://api.bilibili.com/x/v2/reply?type=1&oid=${aid}&sort=0`, headers: { 'User-Agent': config.ua, - 'Referer': `https://www.bilibili.com/video/av${aid}`, - } + Referer: `https://www.bilibili.com/video/av${aid}`, + }, }); const data = response.data.data.replies; @@ -38,7 +38,7 @@ module.exports = async (ctx) => { title: `${item.member.uname} : ${item.content.message}`, description: `#${item.floor}
${item.member.uname} : ${item.content.message}`, pubDate: new Date(item.ctime * 1000).toUTCString(), - link: `https://www.bilibili.com/video/av${aid}/#reply${item.rpid}` + link: `https://www.bilibili.com/video/av${aid}/#reply${item.rpid}`, })), }; -}; \ No newline at end of file +}; diff --git a/routes/bilibili/video.js b/routes/bilibili/video.js index 4f2494b87b8ae5..b6b367f7c04a46 100644 --- a/routes/bilibili/video.js +++ b/routes/bilibili/video.js @@ -10,11 +10,11 @@ module.exports = async (ctx) => { url: 'https://space.bilibili.com/ajax/member/GetInfo', headers: { 'User-Agent': config.ua, - 'Referer': `https://space.bilibili.com/${uid}/`, + Referer: `https://space.bilibili.com/${uid}/`, 'Content-Type': 'application/x-www-form-urlencoded', }, data: qs.stringify({ - mid: uid + mid: uid, }), }); const name = nameResponse.data.data.name; @@ -24,8 +24,8 @@ module.exports = async (ctx) => { url: `https://space.bilibili.com/ajax/member/getSubmitVideos?mid=${uid}`, headers: { 'User-Agent': config.ua, - 'Referer': `https://space.bilibili.com/${uid}/` - } + Referer: `https://space.bilibili.com/${uid}/`, + }, }); const data = response.data; @@ -33,11 +33,14 @@ module.exports = async (ctx) => { title: `${name} 的 bilibili 空间`, link: `https://space.bilibili.com/${uid}`, description: `${name} 的 bilibili 空间`, - item: data.data && data.data.vlist && data.data.vlist.map((item) => ({ - title: item.title, - description: `${item.description}
`, - pubDate: new Date(item.created * 1000).toUTCString(), - link: `https://www.bilibili.com/video/av${item.aid}` - })), + item: + data.data && + data.data.vlist && + data.data.vlist.map((item) => ({ + title: item.title, + description: `${item.description}
`, + pubDate: new Date(item.created * 1000).toUTCString(), + link: `https://www.bilibili.com/video/av${item.aid}`, + })), }; -}; \ No newline at end of file +}; diff --git a/routes/biquge/chapter.js b/routes/biquge/chapter.js index 97b0b70be2057f..1d3fb107d499f5 100644 --- a/routes/biquge/chapter.js +++ b/routes/biquge/chapter.js @@ -13,25 +13,33 @@ module.exports = async (ctx) => { url: `${baseUrl}${id}/`, headers: { 'User-Agent': config.ua, - 'Host':'www.biquge5200.com', - 'Referer': `${baseUrl}${id}/` + Host: 'www.biquge5200.com', + Referer: `${baseUrl}${id}/`, }, // responseEncoding: 'gbk', //该配置项在 0.18版本中没有打包进去 - responseType: 'arraybuffer' + responseType: 'arraybuffer', }); const responseHtml = iconv.decode(response.data, 'GBK'); // console.log('responseHtml',responseHtml); const $ = cheerio.load(responseHtml); - const title = $('#list>dl>dt>b').eq(0).text(); - const description = $('#intro>p').eq(0).text(); - const cover_url = $('#fmimg>img').eq(0).attr('src'); + const title = $('#list>dl>dt>b') + .eq(0) + .text(); + const description = $('#intro>p') + .eq(0) + .text(); + const cover_url = $('#fmimg>img') + .eq(0) + .attr('src'); const list = $('dd', '#list>dl').slice(0, 9); const chapter_item = []; for (let i = 0; i < list.length; i++) { - const el = $(list[i]).find('a').eq(0); + const el = $(list[i]) + .find('a') + .eq(0); const item = { title: el.text(), - link: el.attr('href') + link: el.attr('href'), }; chapter_item.push(item); } diff --git a/routes/dapenti/tugua.js b/routes/dapenti/tugua.js index 79b36c73faf8bc..2a18a81e73e6d5 100644 --- a/routes/dapenti/tugua.js +++ b/routes/dapenti/tugua.js @@ -6,49 +6,51 @@ const iconv = require('iconv-lite'); module.exports = async (ctx) => { const listRes = await axios({ method: 'get', - url: `https://www.dapenti.com/blog/blog.asp?name=xilei&subjectid=70`, + url: 'https://www.dapenti.com/blog/blog.asp?name=xilei&subjectid=70', headers: { 'User-Agent': config.ua, - 'Referer': `https://www.dapenti.com/blog/blog.asp?name=xilei&subjectid=70`, + Referer: 'https://www.dapenti.com/blog/blog.asp?name=xilei&subjectid=70', }, // 喷嚏网编码为GBK,需要转码 // 转码需要设定返回数据的格式,其可选项是arraybuffer,blob,document,json,text,stream // 默认为json - responseType: 'arraybuffer' + responseType: 'arraybuffer', }); // 转码 const data = iconv.decode(listRes.data, 'gb2312'); const $ = cheerio.load(data); // 只取最近的三个图卦,取全文rss - const list = $('li','ul').slice(0,3); - let result_item = []; - //为了避免async/await嵌套,使用for循环代替map方法 - for(let i=0;i { url: `https://disqus.com/api/3.0/forums/listPosts.json?api_key=${config.disqus.api_key}&forum=${forum}`, headers: { 'User-Agent': config.ua, - 'Referer': 'https://disqus.com/' - } + Referer: 'https://disqus.com/', + }, }); const data = response.data.response; @@ -29,8 +29,8 @@ module.exports = async (ctx) => { url: `https://disqus.com/api/3.0/forums/listThreads.json?api_key=${config.disqus.api_key}&forum=${forum}${threadsQuery}`, headers: { 'User-Agent': config.ua, - 'Referer': 'https://disqus.com/' - } + Referer: 'https://disqus.com/', + }, }); const threads = responseThreads.data.response; @@ -45,8 +45,8 @@ module.exports = async (ctx) => { title: `${item.author.name}: ${item.raw_message > 24 ? item.raw_message.slice(0, 24) + '...' : item.raw_message}`, description: `${item.author.name} 在《${thread.clean_title}》中发表评论: ${item.message}`, pubDate: new Date(item.createdAt).toUTCString(), - link: `${thread.link}/#comment-${item.id}` + link: `${thread.link}/#comment-${item.id}`, }; }), }; -}; \ No newline at end of file +}; diff --git a/routes/dockone/weekly.js b/routes/dockone/weekly.js index cdcc0d96b5e055..fa2534e096aab0 100644 --- a/routes/dockone/weekly.js +++ b/routes/dockone/weekly.js @@ -3,10 +3,10 @@ const cheerio = require('cheerio'); const config = require('../../config'); function replaceEmpty(str) { - return str.replace(' ',''); + return str.replace(' ', ''); } -const baseUrl='http://weekly.dockone.io' +const baseUrl = 'http://weekly.dockone.io'; module.exports = async (ctx) => { const url = `${baseUrl}/issues`; @@ -16,26 +16,29 @@ module.exports = async (ctx) => { url: url, headers: { 'User-Agent': config.ua, - Referer: url - } + Referer: url, + }, }); const data = response.data; const $ = cheerio.load(data); const list = $('ul.i.issues>li'); - ctx.state.data = { title: $('title').text(), link: url, description: $('meta[name="description"]').attr('content') || $('title').text(), - item: list && list.map((item,index) => { - item=$(index); - return { - title:`${replaceEmpty(item.find('a>h3>time').text())}[${replaceEmpty(item.find('a>h3>strong').text())}]`, - description:item.find('a>ul>li').text(), - link:`${baseUrl}${item.find('a').attr('href')}` - }; - }).get(), + item: + list && + list + .map((item, index) => { + item = $(index); + return { + title: `${replaceEmpty(item.find('a>h3>time').text())}[${replaceEmpty(item.find('a>h3>strong').text())}]`, + description: item.find('a>ul>li').text(), + link: `${baseUrl}${item.find('a').attr('href')}`, + }; + }) + .get(), }; }; diff --git a/routes/douban/later.js b/routes/douban/later.js index a5728ffb287859..024364065f8684 100644 --- a/routes/douban/later.js +++ b/routes/douban/later.js @@ -13,7 +13,7 @@ module.exports = async (ctx) => { item: movieList.map((item) => ({ title: item.title, description: `标题:${item.title}
影片类型:${item.genres.join(' | ')}
评分:${item.rating.stars === '00' ? '无' : item.rating.average}
`, - link: item.alt + link: item.alt, })), }; -}; \ No newline at end of file +}; diff --git a/routes/douban/playing.js b/routes/douban/playing.js index 621846590e6e35..b71c02281b8878 100644 --- a/routes/douban/playing.js +++ b/routes/douban/playing.js @@ -6,7 +6,7 @@ module.exports = async (ctx) => { const response = await axios({ method: 'get', url: 'https://api.douban.com/v2/movie/in_theaters', - params: { city } + params: { city }, }); const movieList = score ? response.data.subjects.filter((item) => item.rating.average >= score) : response.data.subjects; @@ -16,7 +16,7 @@ module.exports = async (ctx) => { item: movieList.map((item) => ({ title: item.title, description: `标题:${item.title}
影片类型:${item.genres.join(' | ')}
评分:${item.rating.average}
`, - link: item.alt + link: item.alt, })), }; -}; \ No newline at end of file +}; diff --git a/routes/douban/ustop.js b/routes/douban/ustop.js index 40f6b19073f8ec..c22745a600257a 100644 --- a/routes/douban/ustop.js +++ b/routes/douban/ustop.js @@ -15,8 +15,8 @@ module.exports = async (ctx) => { return { title: item.title, description: `标题:${item.title}
影片类型:${item.genres.join(' | ')}
评分:${item.rating.stars === '00' ? '无' : item.rating.average}
`, - link: item.alt + link: item.alt, }; }), }; -}; \ No newline at end of file +}; diff --git a/routes/express/express.js b/routes/express/express.js index 2950f580e2d228..eabfe11eeaec6e 100644 --- a/routes/express/express.js +++ b/routes/express/express.js @@ -10,8 +10,8 @@ module.exports = async (ctx) => { url: `https://www.kuaidi100.com/query?type=${company}&postid=${number}`, headers: { 'User-Agent': config.ua, - 'Referer': 'https://www.kuaidi100.com' - } + Referer: 'https://www.kuaidi100.com', + }, }); const data = response.data.data; @@ -24,7 +24,7 @@ module.exports = async (ctx) => { title: item.context, description: item.context, pubDate: new Date(item.time || item.ftime).toUTCString(), - link: item.context + link: item.context, })), }; -}; \ No newline at end of file +}; diff --git a/routes/geektime/column.js b/routes/geektime/column.js index 84c8463a2e41f5..ca97c8067528aa 100644 --- a/routes/geektime/column.js +++ b/routes/geektime/column.js @@ -10,12 +10,12 @@ module.exports = async (ctx) => { url: 'https://time.geekbang.org/serv/v1/column/intro', headers: { 'User-Agent': config.ua, - 'Referer': 'https://time.geekbang.org/', - 'Content-Type': 'application/json' + Referer: 'https://time.geekbang.org/', + 'Content-Type': 'application/json', }, data: { - cid: column_id - } + cid: column_id, + }, }); const intro_data = intro_response.data.data; @@ -26,12 +26,12 @@ module.exports = async (ctx) => { url: 'https://time.geekbang.org/serv/v1/column/articles/latest', headers: { 'User-Agent': config.ua, - 'Referer': 'https://time.geekbang.org/', - 'Content-Type': 'application/json' + Referer: 'https://time.geekbang.org/', + 'Content-Type': 'application/json', }, data: { - cid: column_id - } + cid: column_id, + }, }); const articles = latest_response.data.data.list; @@ -44,7 +44,7 @@ module.exports = async (ctx) => { title: item.article_title, description: item.article_summary, pubDate: new Date(item.article_ctime * 1000).toUTCString(), - link: `https://time.geekbang.org/column/article/${item.id}` + link: `https://time.geekbang.org/column/article/${item.id}`, })), }; -}; \ No newline at end of file +}; diff --git a/routes/instagram/user.js b/routes/instagram/user.js index ee6f242da68eeb..0e3951f7b4dce3 100644 --- a/routes/instagram/user.js +++ b/routes/instagram/user.js @@ -10,8 +10,8 @@ module.exports = async (ctx) => { url: `https://www.instagram.com/${id}/`, headers: { 'User-Agent': config.ua, - 'Referer': `https://www.instagram.com/${id}/` - } + Referer: `https://www.instagram.com/${id}/`, + }, }); const data = JSON.parse(response.data.match(/