Files
RSSHub/lib/v2/nippon/index.js
Laam Pui 81cd715ed0 feat(route): add nippon.com (#7312)
* feat: add nippon.com

* fix: nippon route

* fix: nippon.com route

* refactor: nippon route v2

* fix: nippon

* Update lib/v2/nippon/index.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

Co-authored-by: Tony <TonyRL@users.noreply.github.com>
2022-02-01 01:04:03 +08:00

32 lines
1.0 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const category = ctx.params.category ?? 'Politics';
const path = category === 'Science,Technology' ? 'condition4' : 'category_code';
const res = await got.get(`https://www.nippon.com/api/search/cn/${path}/20/1/${category}?t=${Date.now()}`);
const list = res.data.body.dataList.map((item) => ({
title: item.title,
link: `https://www.nippon.com/${item.pub_url}`,
pubDate: item.pub_date,
}));
const item = await Promise.all(
list.slice(0, 10).map((item) =>
ctx.cache.tryGet(item.link, async () => {
const res = await got.get(item.link);
const $ = cheerio.load(res.data);
item.description = $('.editArea').html();
return item;
})
)
);
ctx.state.data = {
title: `走进日本 - ${category}`,
link: 'https://www.nippon.com/cn/economy/',
item,
};
};