diff --git a/docs/new-media.md b/docs/new-media.md index e7d067a73f..e13843510f 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1302,6 +1302,30 @@ Supported sub-sites: +## 白话区块链 + +### 首页 + + + +### 快讯 + + + +### 科普 + + + +| latest | bitcoin | ethereum | defi | inter_blockchain | mining | safety | satoshi_nakomoto | public_blockchain | +| ------ | ------- | -------- | ---- | ---------------- | ------ | ------ | ---------------- | ----------------- | +| 最新 | 比特币 | 以太坊 | DeFi | 跨链 | 挖矿 | 安全 | 中本聪 | 公链 | + + + +### 专栏 + + + ## 白鲸出海 ### 首页最新帖子 diff --git a/lib/v2/hellobtc/information.js b/lib/v2/hellobtc/information.js new file mode 100644 index 0000000000..0083742332 --- /dev/null +++ b/lib/v2/hellobtc/information.js @@ -0,0 +1,51 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +const rootUrl = 'https://www.hellobtc.com'; + +const channelSelector = { + latest: 'div.index_tabs_container.js-tabs-container > div:nth-child(1)', + application: 'div.index_tabs_container.js-tabs-container > div:nth-child(2)', +}; + +const titleMap = { + latest: '最新', + application: '应用', +}; + +module.exports = async (ctx) => { + const channel = ctx.params.channel ?? 'latest'; + const url = rootUrl; + + const response = await got(url); + const $ = cheerio.load(response.data); + const list = $(channelSelector[channel]) + .find('div.new_item') + .map((_, item) => ({ + title: $(item).find('h2').text(), + link: $(item).find('a').attr('href'), + })) + .get(); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got(item.link); + const content = cheerio.load(detailResponse.data); + + item.description = content('#nr').html(); + item.pubDate = timezone(parseDate(content('span.date').text(), 'YYYY-MM-DD HH:mm:ss'), +8); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `白话区块链 - 首页 ${titleMap[channel]}`, + link: url, + item: items, + }; +}; diff --git a/lib/v2/hellobtc/kepu.js b/lib/v2/hellobtc/kepu.js new file mode 100644 index 0000000000..628e5a89cd --- /dev/null +++ b/lib/v2/hellobtc/kepu.js @@ -0,0 +1,64 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const rootUrl = 'https://www.hellobtc.com'; + +const channelSelector = { + latest: 'div.index_tabs_container.js-tabs-container > div:nth-child(1)', + bitcoin: 'div.index_tabs_container.js-tabs-container > div:nth-child(2)', + ethereum: 'div.index_tabs_container.js-tabs-container > div:nth-child(3)', + defi: 'div.index_tabs_container.js-tabs-container > div:nth-child(4)', + inter_blockchain: 'div.index_tabs_container.js-tabs-container > div:nth-child(5)', + mining: 'div.index_tabs_container.js-tabs-container > div:nth-child(6)', + safety: 'div.index_tabs_container.js-tabs-container > div:nth-child(7)', + satoshi_nakamoto: 'div.index_tabs_container.js-tabs-container > div:nth-child(8)', + public_blockchain: 'div.index_tabs_container.js-tabs-container > div:nth-child(9)', +}; + +const titleMap = { + latest: '最新', + bitcoin: '比特币', + ethereum: '以太坊', + defi: 'DeFi', + inter_blockchain: '跨链', + mining: '挖矿', + safety: '安全', + satoshi_nakamoto: '中本聪', + public_blockchain: '公链', +}; + +module.exports = async (ctx) => { + const channel = ctx.params.channel ?? 'latest'; + const url = `${rootUrl}/kepu.html`; + + const response = await got(url); + const $ = cheerio.load(response.data); + const list = $(channelSelector[channel]) + .find('div.new_item') + .map((_, item) => ({ + title: $(item).find('a').text(), + link: $(item).find('a').attr('href'), + })) + .get(); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got(item.link); + const content = cheerio.load(detailResponse.data); + + item.description = content('#js_content') + .html() + .replace(/()/g, '$1src$2'); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `白话区块链 - 科普 ${titleMap[channel]}`, + link: url, + item: items, + }; +}; diff --git a/lib/v2/hellobtc/maintainer.js b/lib/v2/hellobtc/maintainer.js new file mode 100644 index 0000000000..1737b1e67f --- /dev/null +++ b/lib/v2/hellobtc/maintainer.js @@ -0,0 +1,6 @@ +module.exports = { + '/information/:channel?': ['Fatpandac'], + '/news': ['Fatpandac'], + '/kepu/:channel?': ['Fatpandac'], + '/topic/:id': ['Fatpandac'], +}; diff --git a/lib/v2/hellobtc/news.js b/lib/v2/hellobtc/news.js new file mode 100644 index 0000000000..5fee1e999e --- /dev/null +++ b/lib/v2/hellobtc/news.js @@ -0,0 +1,29 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +const rootUrl = 'https://www.hellobtc.com'; + +module.exports = async (ctx) => { + const url = `${rootUrl}/news`; + + const response = await got(url); + const $ = cheerio.load(response.data); + const items = $('nav.js-nav') + .find('div.item') + .map((_, item) => ({ + title: $(item).find('h2').text(), + link: $(item).find('a').attr('href'), + description: $(item).find('div.sub').text(), + pubDate: timezone(parseDate($(item).find('span.date').text(), 'MM-DD HH:mm'), +8), + })) + .filter((item) => item) + .get(); + + ctx.state.data = { + title: `白话区块链 - 快讯`, + link: url, + item: items, + }; +}; diff --git a/lib/v2/hellobtc/radar.js b/lib/v2/hellobtc/radar.js new file mode 100644 index 0000000000..dd659a91ad --- /dev/null +++ b/lib/v2/hellobtc/radar.js @@ -0,0 +1,85 @@ +module.exports = { + 'hellobtc.com': { + _name: '白话区块链', + '.': [ + { + title: '首页-最新', + docs: 'https://docs.rsshub.app/new-media.html#bai-hua-qu-kuai-lian', + source: ['/'], + target: '/hellobtc/information/latest', + }, + { + title: '首页-应用', + docs: 'https://docs.rsshub.app/new-media.html#bai-hua-qu-kuai-lian', + source: ['/'], + target: '/hellobtc/information/application', + }, + { + title: '快讯', + docs: 'https://docs.rsshub.app/new-media.html#bai-hua-qu-kuai-lian', + source: ['/news'], + target: '/hellobtc/news', + }, + { + title: '科普-最新', + docs: 'https://docs.rsshub.app/new-media.html#bai-hua-qu-kuai-lian', + source: ['/kepu.html'], + target: '/hellobtc/kepu/latest', + }, + { + title: '科普-比特币', + docs: 'https://docs.rsshub.app/new-media.html#bai-hua-qu-kuai-lian', + source: ['/kepu.html'], + target: '/hellobtc/kepu/bitcoin', + }, + { + title: '科普-以太坊', + docs: 'https://docs.rsshub.app/new-media.html#bai-hua-qu-kuai-lian', + source: ['/kepu.html'], + target: '/hellobtc/kepu/ethereum', + }, + { + title: '科普-DeFi', + docs: 'https://docs.rsshub.app/new-media.html#bai-hua-qu-kuai-lian', + source: ['/kepu.html'], + target: '/hellobtc/kepu/defi', + }, + { + title: '科普-跨链', + docs: 'https://docs.rsshub.app/new-media.html#bai-hua-qu-kuai-lian', + source: ['/kepu.html'], + target: '/hellobtc/kepu/inter_blockchain', + }, + { + title: '科普-挖矿', + docs: 'https://docs.rsshub.app/new-media.html#bai-hua-qu-kuai-lian', + source: ['/kepu.html'], + target: '/hellobtc/kepu/mining', + }, + { + title: '科普-安全', + docs: 'https://docs.rsshub.app/new-media.html#bai-hua-qu-kuai-lian', + source: ['/kepu.html'], + target: '/hellobtc/kepu/safety', + }, + { + title: '科普-中本聪', + docs: 'https://docs.rsshub.app/new-media.html#bai-hua-qu-kuai-lian', + source: ['/kepu.html'], + target: '/hellobtc/kepu/satoshi_nakamoto', + }, + { + title: '科普-公链', + docs: 'https://docs.rsshub.app/new-media.html#bai-hua-qu-kuai-lian', + source: ['/kepu.html'], + target: '/hellobtc/kepu/public_blockchain', + }, + { + title: '专栏', + docs: 'https://docs.rsshub.app/new-media.html#bai-hua-qu-kuai-lian', + source: ['/topic/:id'], + target: (params) => `/hellobtc/topic/${params.id.split('.')[0]}`, + }, + ], + }, +}; diff --git a/lib/v2/hellobtc/router.js b/lib/v2/hellobtc/router.js new file mode 100644 index 0000000000..fa470dfae5 --- /dev/null +++ b/lib/v2/hellobtc/router.js @@ -0,0 +1,6 @@ +module.exports = function (router) { + router.get('/information/:channel?', require('./information')); + router.get('/news', require('./news')); + router.get('/kepu/:channel?', require('./kepu')); + router.get('/topic/:id', require('./topic')); +}; diff --git a/lib/v2/hellobtc/topic.js b/lib/v2/hellobtc/topic.js new file mode 100644 index 0000000000..27015a5277 --- /dev/null +++ b/lib/v2/hellobtc/topic.js @@ -0,0 +1,43 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +const rootUrl = 'https://www.hellobtc.com'; + +module.exports = async (ctx) => { + const id = ctx.params.id; + const url = `${rootUrl}/topic/${id}.html`; + + const response = await got(url); + const $ = cheerio.load(response.data); + const title = $('div.content > h1').text(); + const list = $('div.tab_pane') + .find('div.new_item') + .map((_, item) => ({ + title: $(item).find('h2').text(), + link: $(item).find('a').attr('href'), + })) + .filter((item) => item) + .get(); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got(item.link); + const content = cheerio.load(detailResponse.data); + + item.description = content('#nr').html(); + item.pubDate = timezone(parseDate(content('span.date').text(), 'YYYY-MM-DD HH:mm:ss'), +8); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `白话区块链 - ${title}专栏`, + link: url, + item: items, + }; +};