From 0a179a9817d26b75424366c4e753760778d3fc56 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Fri, 11 Jun 2021 03:43:04 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E6=9C=9D=E6=97=A5?= =?UTF-8?q?=E6=96=B0=E8=81=9E=E3=83=87=E3=82=B8=E3=82=BF=E3=83=AB=E5=9C=B0?= =?UTF-8?q?=E5=9F=9F=20(#7659)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: NeverBehave --- docs/traditional-media.md | 42 ++++++++++++++++++++++++++++ lib/router.js | 12 ++++++-- lib/routes/asahi/area.js | 58 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 lib/routes/asahi/area.js diff --git a/docs/traditional-media.md b/docs/traditional-media.md index fc1ee8ac8..9a9a71eab 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -1022,6 +1022,48 @@ category 对应的关键词有 ## 朝日新聞デジタル + + +北海道・東北 + +| 北海道 | 青森 | 秋田 | 岩手 | 山形 | 宮城 | 福島 | +| -------- | ------ | ----- | ----- | -------- | ------ | --------- | +| 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 | + + + +## 朝日新聞中文網(繁體中文版) + ::: tip 提示 朝日新闻中文网已于 2021 年 3 月 31 日关闭。 diff --git a/lib/router.js b/lib/router.js index 6deaf0e21..a035e7d3d 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/asahi/area.js b/lib/routes/asahi/area.js new file mode 100644 index 000000000..89c6d0581 --- /dev/null +++ b/lib/routes/asahi/area.js @@ -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: '朝日新聞社のニュースサイト、朝日新聞デジタルの社会ニュースについてのページです', + }; +};