@@ -204,6 +204,7 @@ category 对应的关键词有
|
||||
## 人民日报
|
||||
|
||||
<Route name="观点" author="LogicJake" example="/people/opinion/223228" path="/people/opinion/:id" :paramsDesc="['板块id,可在 URL 中找到']"/>
|
||||
<Route name="习近平系列重要讲话" author="LogicJake" example="/people/xjpjh" path="/people/xjpjh/:keyword?/:year?" :paramsDesc="['关键词,默认不填','年份,默认all']"/>
|
||||
|
||||
## 半月谈
|
||||
|
||||
|
||||
@@ -1190,6 +1190,7 @@ router.get('/banyuetan/:name', require('./routes/banyuetan'));
|
||||
|
||||
// 人民日报
|
||||
router.get('/people/opinion/:id', require('./routes/people/opinion'));
|
||||
router.get('/people/xjpjh/:keyword?/:year?', require('./routes/people/xjpjh'));
|
||||
|
||||
// gamersky
|
||||
router.get('/gamersky/news', require('./routes/gamersky/news'));
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
const axios = require('../../utils/axios');
|
||||
const cheerio = require('cheerio');
|
||||
const url = require('url');
|
||||
|
||||
const host = 'http://jhsjk.people.cn';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let keyword = ctx.params.keyword || 'all';
|
||||
let year = ctx.params.year || 0;
|
||||
|
||||
let title = '习近平系列重要讲话';
|
||||
title = title + '-' + keyword;
|
||||
if (keyword === 'all') {
|
||||
keyword = '';
|
||||
}
|
||||
if (year !== 0) {
|
||||
title = title + '-' + year;
|
||||
year = year - 1811;
|
||||
} else {
|
||||
title = title + '-all';
|
||||
}
|
||||
|
||||
const link = `http://jhsjk.people.cn/result?keywords=${keyword}&year=${year}`;
|
||||
const response = await axios.get(link);
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('ul.list_14.p1_2.clearfix li')
|
||||
.slice(0, 10)
|
||||
.map(function() {
|
||||
const info = {
|
||||
title: $(this)
|
||||
.find('a')
|
||||
.text(),
|
||||
link: $(this)
|
||||
.find('a')
|
||||
.attr('href'),
|
||||
};
|
||||
return info;
|
||||
})
|
||||
.get();
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (info) => {
|
||||
const title = info.title;
|
||||
const itemUrl = url.resolve(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.d2txt_con.clearfix')
|
||||
.html()
|
||||
.trim();
|
||||
|
||||
const single = {
|
||||
title: title,
|
||||
link: itemUrl,
|
||||
description: description,
|
||||
};
|
||||
ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60);
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: title,
|
||||
link: link,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user