diff --git a/docs/traditional-media.md b/docs/traditional-media.md index 1f1842dca..82ddfff69 100644 --- a/docs/traditional-media.md +++ b/docs/traditional-media.md @@ -217,3 +217,29 @@ category 对应的关键词有 ## The Economist + +## 朝日新聞中文網 + + + +版块: + +| 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 | +| ---- | ------- | ----- | ---- | +| 資訊 | 風景 | 體驗 | 交通 | + + diff --git a/lib/router.js b/lib/router.js index 04fdf68ef..235b3841c 100755 --- a/lib/router.js +++ b/lib/router.js @@ -1319,4 +1319,8 @@ router.get('/gradcafe/result', require('./routes/gradcafe/result')); // The Economist router.get('/the-economist/gre-vocabulary', require('./routes/the-economist/gre-vocabulary')); +// 朝日新聞中文網 +router.get('/asahichinese-f/:category/:subCate', require('./routes/asahichinese-f/index')); +router.get('/asahichinese-f/:category', require('./routes/asahichinese-f/index')); + module.exports = router; diff --git a/lib/routes/asahichinese-f/index.js b/lib/routes/asahichinese-f/index.js new file mode 100644 index 000000000..a43ef3c71 --- /dev/null +++ b/lib/routes/asahichinese-f/index.js @@ -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-f.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-f.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), 24 * 60 * 60); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: `${iTitle}-朝日新聞中文網`, + link: link, + item: out, + }; +};