feat(route): add 朝日新聞デジタル地域 (#7659)

Co-authored-by: NeverBehave <gayhub@never.pet>
This commit is contained in:
Ethan Shen 2021-06-11 03:43:04 +08:00 committed by GitHub
parent 5284b7e18d
commit 0a179a9817
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 109 additions and 3 deletions

View File

@ -1022,6 +1022,48 @@ category 对应的关键词有
## 朝日新聞デジタル
<Route author="nczitzk" example="/asahi/area/hokkaido" path="/asahi/area/:id" :paramsDesc="['地方 id见下表']">
北海道・東北
| 北海道 | 青森 | 秋田 | 岩手 | 山形 | 宮城 | 福島 |
| -------- | ------ | ----- | ----- | -------- | ------ | --------- |
| hokkaido | aomori | akita | iwate | yamagata | miyagi | fukushima |
関東
| 群馬 | 茨城 | 栃木 | 埼玉 | 千葉 | 東京 | 神奈川 |
| ----- | ------- | ------- | ------- | ----- | ----- | -------- |
| gunma | ibaraki | tochigi | saitama | chiba | tokyo | kanagawa |
東海・甲信越
| 静岡 | 岐阜 | 愛知 | 三重 | 新潟 | 山梨 | 長野 |
| -------- | ---- | ----- | ---- | ------- | --------- | ------ |
| shizuoka | gifu | aichi | mie | niigata | yamanashi | nagano |
近畿・北陸
| 滋賀 | 京都 | 奈良 | 和歌山 | 大阪 | 兵庫 | 富山 | 石川 | 福井 |
| ----- | ----- | ---- | -------- | ----- | ----- | ------ | -------- | ----- |
| shiga | kyoto | nara | wakayama | osaka | hyogo | toyama | ishikawa | fukui |
中国・四国
| 鳥取 | 島根 | 岡山 | 広島 | 山口 | 香川 | 愛媛 | 徳島 | 高知 |
| ------- | ------- | ------- | --------- | --------- | ------ | ----- | --------- | ----- |
| tottori | shimane | okayama | hiroshima | yamaguchi | kagawa | ehime | tokushima | kochi |
九州・沖縄
| 福岡 | 大分 | 宮崎 | 鹿児島 | 佐賀 | 長崎 | 熊本 | 沖縄 |
| ------- | ---- | -------- | --------- | ---- | -------- | -------- | ------- |
| fukuoka | oita | miyazaki | kagoshima | saga | nagasaki | kumamoto | okinawa |
</Route>
## 朝日新聞中文網(繁體中文版)
::: tip 提示
朝日新闻中文网已于 2021 年 3 月 31 日关闭。

View File

@ -1718,9 +1718,15 @@ router.get('/the-economist/:endpoint', require('./routes/the-economist/full'));
router.get('/shuhui/comics/:id', require('./routes/shuhui/comics'));
// 朝日新闻
router.get('/asahi/:genre?/:category?', require('./routes/asahi/index'));
router.get('/asahichinese-j/:genre?/:category?', require('./routes/asahi/index'));
router.get('/asahichinese-f/:genre?/:category?', require('./routes/asahi/index'));
router.get('/asahi/area/:id', require('./routes/asahi/area'));
// 朝日新聞中文网(简体中文版)
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', require('./routes/asahichinese-f/index'));
// 7x24小时快讯
router.get('/fx678/kx', require('./routes/fx678/kx'));

58
lib/routes/asahi/area.js Normal file
View File

@ -0,0 +1,58 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const id = ctx.params.id;
const rootUrl = 'https://www.asahi.com';
const currentUrl = `${rootUrl}/area/${id}`;
const response = await got({
method: 'get',
url: currentUrl,
});
const $ = cheerio.load(response.data);
$('.Time').remove();
const list = $('#MainInner .Section .List li a')
.slice(0, 6)
.map((_, item) => {
item = $(item);
const link = item.attr('href');
return {
link: link.indexOf('//') < 0 ? `${rootUrl}${link}` : `https:${link}`,
};
})
.get();
const items = await Promise.all(
list.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const content = cheerio.load(detailResponse.data);
content('._30SFw, .-Oj2D, .notPrint').remove();
item.description = content('._3YqJ1').html();
item.title = content('meta[name="TITLE"]').attr('content');
item.pubDate = Date.parse(content('meta[name="pubdate"]').attr('content'));
return item;
})
)
);
ctx.state.data = {
title: $('title').text(),
link: currentUrl,
item: items,
description: '朝日新聞社のニュースサイト、朝日新聞デジタルの社会ニュースについてのページです',
};
};