feat: 朝日新聞中文网简体中文版 (#2146)

* 修正了朝日新闻中文网繁体中文版的文档

* 增加了朝日新聞中文网简体中文版

* 提交route.js
This commit is contained in:
格莱
2019-05-17 18:05:18 +08:00
committed by DIYgod
parent b1bbdf6511
commit 75d9cb1e2a
3 changed files with 145 additions and 4 deletions

View File

@@ -282,11 +282,39 @@ category 对应的关键词有
</Route> </Route>
## 朝日新聞中文 ## 朝日新聞中文网(简体中文版)
### 新闻分类 ### 新闻分类
<Route author="qiwihui" example="/sina/society" path="/sina/discovery/:category/:subCate?" :paramsDesc="['版块', '子块']"> <Route author="zhouchang29" example="/asahichinese-j/society" path="/asahichinese-j/:category/:subCate?" :paramsDesc="['版块', '子块']">
版块:
| society | politics_economy | cool_japan | travel | sports | business | technology | world | opinion |
| -------- | ---------------- | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- |
| 日本社会 | 政治・经济 | 文娱・生活 | 旅游・活动 | 体育・奥运 | 商务・商品 | IT・科技 | 国际・东亚 | 观点・专栏 |
版块 `cool_japan``travel` 包含子版块:
`cool_japan`
| entertainment | anime | life | style_culture |
| ------------- | ----- | ---------- | ------------- |
| 艺能 | 动漫 | 生活・美食 | 时尚・文化 |
`travel`:
| news | scenery | topic | move |
| ---- | ------- | ----- | ---- |
| 资讯 | 风景 | 体验 | 交通 |
</Route>
## 朝日新聞中文網(繁體中文版)
### 新聞分類
<Route author="qiwihui" example="/asahichinese-f/society" path="/asahichinese-f/:category/:subCate?" :paramsDesc="['版块', '子版块']">
版块: 版块:
@@ -294,7 +322,7 @@ category 对应的关键词有
| -------- | ---------------- | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- | | -------- | ---------------- | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- |
| 國內綜合 | 政治・經濟 | 文化・生活 | 旅遊・活動 | 體育・奧運 | 商業・商品 | IT・科技 | 國際・東亞 | 評論・專欄 | | 國內綜合 | 政治・經濟 | 文化・生活 | 旅遊・活動 | 體育・奧運 | 商業・商品 | IT・科技 | 國際・東亞 | 評論・專欄 |
版块 `cool_japan``travel` 包含子板块子板块: 版块 `cool_japan``travel` 包含子块:
`cool_japan` `cool_japan`

View File

@@ -1260,7 +1260,11 @@ router.get('/the-economist/gre-vocabulary', require('./routes/the-economist/gre-
// 鼠绘漫画 // 鼠绘漫画
router.get('/shuhui/comics/:id', require('./routes/shuhui/comics')); router.get('/shuhui/comics/:id', require('./routes/shuhui/comics'));
// 朝日新聞中文 // 朝日新聞中文网(简体中文版)
router.get('/asahichinese-j/:category/:subCate', require('./routes/asahichinese-j/index'));
router.get('/asahichinese-j/:category', require('./routes/asahichinese-j/index'));
// 朝日新聞中文網(繁體中文版)
router.get('/asahichinese-f/:category/:subCate', require('./routes/asahichinese-f/index')); router.get('/asahichinese-f/:category/:subCate', require('./routes/asahichinese-f/index'));
router.get('/asahichinese-f/:category', require('./routes/asahichinese-f/index')); router.get('/asahichinese-f/:category', require('./routes/asahichinese-f/index'));

View File

@@ -0,0 +1,109 @@
const axios = require('@/utils/axios');
const cheerio = require('cheerio');
const logger = require('@/utils/logger');
const categoryCodes = new Map([
['society', { name: '日本社会', types: {} }],
['politics_economy', { name: '政治・经济', types: {} }],
[
'cool_japan',
{
name: '文娱・生活',
types: {
entertainment: '艺能',
anime: '动漫',
life: '生活・美食',
style_culture: '时尚・文化',
},
},
],
[
'travel',
{
name: '旅游・活动',
types: {
news: '资讯',
scenery: '风景',
topic: '体验',
move: '交通',
},
},
],
['sports', { name: '体育・奥运', types: {} }],
['business', { name: '商务・商品', types: {} }],
['technology', { name: 'IT・科技', types: {} }],
['world', { name: '国际・东亚', types: {} }],
['opinion', { name: '观点・专栏', types: {} }],
]);
const host = 'https://asahichinese-j.com';
module.exports = async (ctx) => {
const category = ctx.params.category;
const type = ctx.params.subCate;
let iTitle = categoryCodes.get(category).name;
let link = `https://asahichinese-j.com/${category}/`;
if (type !== undefined) {
link = link + `${type}/`;
iTitle = iTitle + '-' + categoryCodes.get(category).types[type];
}
const response = await axios.get(link);
const $ = cheerio.load(response.data);
const list = $('ul.List li')
.slice(1, 11)
.map(function() {
const info = {
title: $(this)
.find('a')
.text(),
link: $(this)
.find('a')
.attr('href'),
date: $(this)
.find('span.Date')
.text(),
};
logger.info(info.date);
return info;
})
.get();
const out = await Promise.all(
list.map(async (info) => {
const title = info.title;
const date = info.date;
const itemUrl = host + info.link;
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const response = await axios.get(itemUrl);
const $ = cheerio.load(response.data);
const description = $('div.ArticleText')
.html()
.trim();
const single = {
title: title,
link: itemUrl,
description: description,
pubDate: new Date(date).toUTCString(),
};
ctx.cache.set(itemUrl, JSON.stringify(single));
return Promise.resolve(single);
})
);
ctx.state.data = {
title: `${iTitle}-朝日新聞中文网`,
link: link,
item: out,
};
};