feat: 故事fm/中国日报网 (#2725)

This commit is contained in:
sanmmmm
2019-08-02 17:23:57 +08:00
committed by DIYgod
parent 914034760d
commit bc38bdc93d
7 changed files with 111 additions and 6 deletions

View File

@@ -206,6 +206,12 @@ pageClass: routes
<Route author="Songkeys" example="/gaoqing/latest" path="/gaoqing/latest"/>
## 故事 FM
### 首页
<Route author="sanmmm" example="/storyfm/index" path="/storyfm/index"/>
## 开眼
### 每日精选

View File

@@ -284,7 +284,7 @@ type 为 all 时category 参数不支持 cost 和 free
### 分类目录
<Route author="sanmmm" example="/wikihow/category/饮食与休闲/" path="/wikihow/category/:category/:type" :paramsDesc="['目录分类', '类型']">
<Route author="sanmmm" example="/wikihow/category/饮食与休闲/all" path="/wikihow/category/:category/:type?" :paramsDesc="['目录分类', '类型, 默认为`all`']">
顶级目录分类可在目录分类页[查看](https://zh.wikihow.com/Special:CategoryListing), 支持二级目录
@@ -313,9 +313,9 @@ type 为 all 时category 参数不支持 cost 和 free
<Route author="sanmmm" example="/afdian/explore/hot/所有" path="/afdian/explore/:type/:category?" :paramsDesc="['分类', '目录类型, 默认为 `所有`']">
分类
| 最新 | 推荐 | 最热 |
| ---- | ---- | ---- |
| new | rec | hot |
| 推荐 | 最热 |
| ---- | ---- |
| rec | hot |
目录类型
@@ -1091,7 +1091,7 @@ type 为 all 时category 参数不支持 cost 和 free
### 全屋记
<Route author="sanmmm" example="/yidoutang/case/:type?" path="/yidoutang/case/hot" :paramsDesc="['类型, 默认为`default`']">
<Route author="sanmmm" example="/yidoutang/case/hot" path="/yidoutang/:type?" :paramsDesc="['类型, 默认为`default`']">
类型
@@ -1100,6 +1100,7 @@ type 为 all 时category 参数不支持 cost 和 free
| default | hot | new |
</Route>
## 油价
### 今日油价

View File

@@ -376,3 +376,17 @@ category 对应的关键词有
| 资讯 | 风景 | 体验 | 交通 |
</Route>
## 中国日报
### 英语点津
<Route author="sanmmm" example="/chinadaily/english/thelatest" path="/chinadaily/english/:category" :paramsDesc="['目录分类']">
目录分类
| 最新 | 双语 | 热词 | 口语 | 译词 | 视频 | 听力 | 专栏 | 文件 | 考试 |
| --------- | -------------- | ------------- | --------------- | ------------- | ----------- | -------- | --------- | ------------------------ | ------------ |
| thelatest | news_bilingual | news_hotwords | practice_tongue | trans_collect | video_links | audio_cd | columnist | 5af95d44a3103f6866ee845c | englishexams |
</Route>

View File

@@ -1597,6 +1597,12 @@ router.get('/aliyun/database_month', require('./routes/aliyun/database_month'));
// 礼物说
router.get('/liwushuo/index', require('./routes/liwushuo/index.js'));
// 故事fm
router.get('/storyfm/index', require('./routes/storyfm/index.js'));
// 中国日报
router.get('/chinadaily/english/:category', require('./routes/chinadaily/english.js'));
// leboncoin
router.get('/leboncoin/ad/:query', require('./routes/leboncoin/ad.js'));

View File

@@ -24,7 +24,6 @@ const categoryMap = {
const typeToLabel = {
rec: '推荐',
hot: '人气',
new: '新入驻',
};
module.exports = async (ctx) => {

View File

@@ -0,0 +1,35 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const { category } = ctx.params;
const baseUrl = 'https://language.chinadaily.com.cn';
const url = `${baseUrl}/${category}`;
const response = await got(url);
const $ = cheerio.load(response.data);
const categoryName = $('.CT_title')
.first()
.text();
const items = $('.gy_box')
.map((_, ele) => {
const $item = cheerio.load(ele);
const link = $item('.gy_box_img').attr('href');
const imgUrl = $item('.gy_box_img img').attr('src');
const realImgUrl = imgUrl.includes('http') ? imgUrl : `https:${imgUrl}`;
const title = $item('.gy_box_txt2').text();
const desc = $item('.gy_box_txt3').text();
return {
title,
link,
description: [`<img src="${realImgUrl}"/>`, desc].join('<br/>'),
};
})
.get();
ctx.state.data = {
title: `中国日报 - ${categoryName}`,
description: `中国日报 - ${categoryName}`,
link: url,
item: items,
};
};

View File

@@ -0,0 +1,44 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const url = 'http://storyfm.cn';
const response = await got(url);
const $ = cheerio.load(response.data);
const cnMonth = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
const items = $('.isotope > .isotope-item')
.map((_, ele) => {
const $item = cheerio.load(ele);
const img = $item('.isotope-img-container img').attr('src');
const infoNode = $item('.isotope-index-text').first();
const title = infoNode.find('.soundbyte-podcast-progression-title');
const link = infoNode.find('a.soundbyte-podcast-play-progression').attr('href');
const time = infoNode.find('.fa-clock-o').text();
const date = infoNode.find('.soundbyte-podcast-date-progression').text();
const [month, day, year] = date
.replace(',', '')
.split(' ')
.map((value) => {
if (value.includes('月')) {
const enMongth = cnMonth.findIndex((cnMonthStr) => value.includes(cnMonthStr));
value = enMongth + 1;
}
return value;
});
const pubDate = new Date(`${year}-${month}-${day} ${time}`).toUTCString();
return {
title,
description: [`<img src="${img}"/>`, title].join('<br/>'),
link,
pubDate,
};
})
.get();
ctx.state.data = {
title: '故事说FM',
description: '故事说FM',
link: url,
item: items,
};
};