diff --git a/docs/README.md b/docs/README.md index 3ab0fa5e8..bb5374214 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1270,6 +1270,10 @@ Category 列表: +### NHK + + + ### BBC diff --git a/router.js b/router.js index d586c5dab..5715d67b8 100644 --- a/router.js +++ b/router.js @@ -598,6 +598,9 @@ router.get('/dytt/index', require('./routes/dytt/index')); // 趣头条 router.get('/qutoutiao/category/:cid', require('./routes/qutoutiao/category')); +// NHK NEW WEB EASY +router.get('/nhk/news_web_easy', require('./routes/nhk/news_web_easy')); + // BBC router.get('/bbc/:channel?', require('./routes/bbc/index')); diff --git a/routes/nhk/news_web_easy.js b/routes/nhk/news_web_easy.js new file mode 100644 index 000000000..264a07de5 --- /dev/null +++ b/routes/nhk/news_web_easy.js @@ -0,0 +1,40 @@ +const axios = require('../../utils/axios'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const { data } = await axios.get('https://www3.nhk.or.jp/news/easy/news-list.json'); + const dates = JSON.parse(data.trim())[0]; + + let items = []; + for (const articles of Object.values(dates)) { + for (const article of articles) { + items.push({ + title: article.title, + description: `

${article.title_with_ruby}


`, + guid: article.news_id, + pubDate: new Date(article.news_publication_time).toUTCString(), + link: `https://www3.nhk.or.jp/news/easy/${article.news_id}/${article.news_id}.html`, + }); + } + } + + items = items.sort((a, b) => b.pubDate - a.pubDate).slice(0, 10); + + const promises = []; + const getDetail = async (item) => { + const { data } = await axios.get(item.link); + const $ = cheerio.load(data); + item.description += $('.article-body').html(); + }; + for (const item of items) { + promises.push(getDetail(item)); + } + await Promise.all(promises); + + ctx.state.data = { + title: 'NEWS WEB EASY', + link: 'https://www3.nhk.or.jp/news/easy/', + description: 'NEWS WEB EASYは、小学生・中学生の皆さんや、日本に住んでいる外国人のみなさんに、わかりやすいことば でニュースを伝えるウェブサイトです。', + item: items, + }; +};