feat(route): add 白话区块链 (#9234)

* feat(route): add 白话区块链

* Update lib/v2/hellobtc/information.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/hellobtc/news.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/hellobtc/information.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/hellobtc/kepu.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/hellobtc/topic.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/hellobtc/topic.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* fix(route): add timezone

Co-authored-by: Tony <TonyRL@users.noreply.github.com>
This commit is contained in:
Fatpandac
2022-03-03 19:50:28 +08:00
committed by GitHub
parent 07c5bfee23
commit 25ea6fe393
8 changed files with 308 additions and 0 deletions

View File

@@ -1302,6 +1302,30 @@ Supported sub-sites:
<Route author="hillerliao" example="/8btc/news/flash" path="/8btc/news/flash"/>
## 白话区块链
### 首页
<Route author="Fatpandac" example="/hellobtc/information/latest" path="/hellobtc/information/:channel?" :paramsDesc="['类型,可填 `latest``application` 及最新和应用,默认为最新']"/>
### 快讯
<Route author="Fatpandac" example="/hellobtc/news" path="/hellobtc/news"/>
### 科普
<Route author="Fatpandac" example="/hellobtc/kepu/latest" path="/hellobtc/kepu/:channel?" :paramsDesc="['类型,见下表,默认为最新']">
| latest | bitcoin | ethereum | defi | inter_blockchain | mining | safety | satoshi_nakomoto | public_blockchain |
| ------ | ------- | -------- | ---- | ---------------- | ------ | ------ | ---------------- | ----------------- |
| 最新 | 比特币 | 以太坊 | DeFi | 跨链 | 挖矿 | 安全 | 中本聪 | 公链 |
</Route>
### 专栏
<Route author="Fatpandac" example="/hellobtc/topic/276" path="/hellobtc/topic/:id" :paramsDesc="['专栏 ID可在网址中获取']"/>
## 白鲸出海
### 首页最新帖子

View File

@@ -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,
};
};

64
lib/v2/hellobtc/kepu.js Normal file
View File

@@ -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(/(<img.*?)data-src(.*?>)/g, '$1src$2');
return item;
})
)
);
ctx.state.data = {
title: `白话区块链 - 科普 ${titleMap[channel]}`,
link: url,
item: items,
};
};

View File

@@ -0,0 +1,6 @@
module.exports = {
'/information/:channel?': ['Fatpandac'],
'/news': ['Fatpandac'],
'/kepu/:channel?': ['Fatpandac'],
'/topic/:id': ['Fatpandac'],
};

29
lib/v2/hellobtc/news.js Normal file
View File

@@ -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,
};
};

85
lib/v2/hellobtc/radar.js Normal file
View File

@@ -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]}`,
},
],
},
};

View File

@@ -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'));
};

43
lib/v2/hellobtc/topic.js Normal file
View File

@@ -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,
};
};