diff --git a/docs/new-media.md b/docs/new-media.md index 50dfe6795a..f57331c9af 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -4114,6 +4114,35 @@ wechat-feeds 来源[已停止更新](https://github.com/hellodword/wechat-feeds/ +## 重构 + +### 推荐 + + + +### 快讯 + + + +### 资讯 + + + +| 分类 | id | +| ---- | ------------------ | +| 全部 | posts | +| NFT | non-fungible-token | +| DAO | dao | +| Web3 | web3 | +| 安全 | security | +| 政策 | global-policy | +| 元宇宙 | metaverse | +| 区块链 | blockchain | +| 融资新闻 | financing-news | +| 趋势观察 | trend-observation | + + + ## 眾新聞 ### 眾聞 diff --git a/lib/v2/allrecode/index.js b/lib/v2/allrecode/index.js new file mode 100644 index 0000000000..974ec0aa9e --- /dev/null +++ b/lib/v2/allrecode/index.js @@ -0,0 +1,65 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const category = ctx.params.category ?? 'posts'; + + const rootUrl = 'https://allrecode.com'; + const currentUrl = `${rootUrl}/${category}`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + let items = $('h3 a') + .toArray() + .map((item) => { + item = $(item); + + return { + title: item.text(), + link: item.attr('href'), + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + item.author = content('.author').text(); + item.category = content('meta[name="keywords"]').attr('content').split(','); + item.pubDate = timezone( + parseDate( + content('.edit') + .text() + .match(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}/) + ), + +8 + ); + + content('.edit, .shang').remove(); + + item.description = content('.article-content').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/allrecode/maintainer.js b/lib/v2/allrecode/maintainer.js new file mode 100644 index 0000000000..0bd5ca557a --- /dev/null +++ b/lib/v2/allrecode/maintainer.js @@ -0,0 +1,5 @@ +module.exports = { + '/news': ['nczitzk'], + '/recommends': ['nczitzk'], + '/:category?': ['nczitzk'], +}; diff --git a/lib/v2/allrecode/news.js b/lib/v2/allrecode/news.js new file mode 100644 index 0000000000..35cc7f24d9 --- /dev/null +++ b/lib/v2/allrecode/news.js @@ -0,0 +1,35 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const rootUrl = 'https://allrecode.com'; + const currentUrl = `${rootUrl}/news`; + + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const items = $('.news-trigger') + .toArray() + .map((item) => { + item = $(item); + + return { + title: item.text(), + link: item.attr('href'), + pubDate: timezone(parseDate(item.parent().prev().text(), 'HH:mm'), +8), + description: item.parent().next().html(), + }; + }); + + ctx.state.data = { + title: $('title').text(), + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/allrecode/radar.js b/lib/v2/allrecode/radar.js new file mode 100644 index 0000000000..9050b9adb1 --- /dev/null +++ b/lib/v2/allrecode/radar.js @@ -0,0 +1,25 @@ +module.exports = { + 'allrecode.com': { + _name: '重构', + '.': [ + { + title: '推荐', + docs: 'https://docs.rsshub.app/news-media.html#chong-gou-tui-jian', + source: ['/recommends', '/'], + target: '/allrecode/recommends', + }, + { + title: '快讯', + docs: 'https://docs.rsshub.app/news-media.html#chong-gou-kuai-xun', + source: ['/news', '/'], + target: '/allrecode/news', + }, + { + title: '资讯', + docs: 'https://docs.rsshub.app/news-media.html#chong-gou-zi-xun', + source: ['/:category', '/'], + target: '/allrecode/:category', + }, + ], + }, +}; diff --git a/lib/v2/allrecode/router.js b/lib/v2/allrecode/router.js new file mode 100644 index 0000000000..624f1c26f9 --- /dev/null +++ b/lib/v2/allrecode/router.js @@ -0,0 +1,4 @@ +module.exports = function (router) { + router.get('/news', require('./news')); + router.get('/:category?', require('./index')); +};