feat: add lifetimes (#6266)
This commit is contained in:
parent
15f6ad9a7b
commit
e51766e340
|
|
@ -1363,6 +1363,18 @@ column 为 third 时可选的 category:
|
|||
|
||||
<Route author="Jeason0228" example="/sspai/tag/apple" path="/sspai/tag/:keyword" :paramsDesc="['关键词']"/>
|
||||
|
||||
## 生命时报
|
||||
|
||||
### 栏目
|
||||
|
||||
<Route author="nczitzk" example="/lifetimes" path="/lifetimes/:category?" :paramsDesc="['栏目,见下表,默认为新闻']">
|
||||
|
||||
| 新闻 | 医药 | 养生 | 生活 | 母亲行动 | 长寿 | 视频 | 时评 | 调查 | 产业经济 |
|
||||
| ---- | -------- | --------------- | ---- | -------- | --------- | ----- | ------------ | ------- | -------- |
|
||||
| news | medicine | healthpromotion | life | mothers | longevity | video | news-comment | hotspot | industry |
|
||||
|
||||
</Route>
|
||||
|
||||
## 生物谷
|
||||
|
||||
### 最新资讯
|
||||
|
|
|
|||
|
|
@ -3513,6 +3513,9 @@ router.get('/uisdc/news', require('./routes/uisdc/news'));
|
|||
router.get('/uisdc/zt/:title?', require('./routes/uisdc/zt'));
|
||||
router.get('/uisdc/topic/:title?/:sort?', require('./routes/uisdc/topic'));
|
||||
|
||||
// 生命时报
|
||||
router.get('/lifetimes/:category?', require('./routes/lifetimes/index'));
|
||||
|
||||
// MakeUseOf
|
||||
router.get('/makeuseof/:category?', require('./routes/makeuseof/index'));
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,100 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const category = ctx.params.category || 'news';
|
||||
|
||||
const rootUrl = 'http://www.lifetimes.cn';
|
||||
const currentUrl = `${rootUrl}/${category.replace('-', '/')}`;
|
||||
|
||||
const apiUrl = `${rootUrl}/api/list?offset=0&limit=20&node=`;
|
||||
let title, list, response;
|
||||
|
||||
switch (category) {
|
||||
case 'hotspot': {
|
||||
title = '调查';
|
||||
response = await got({
|
||||
method: 'get',
|
||||
url: apiUrl + '%22/eh78c0d1d%22',
|
||||
});
|
||||
list = response.data.list.slice(0, 20).map((item) => ({
|
||||
link: `${rootUrl}/article/${item.aid}`,
|
||||
}));
|
||||
break;
|
||||
}
|
||||
case 'industry': {
|
||||
title = '产业经济';
|
||||
response = await got({
|
||||
method: 'get',
|
||||
url: apiUrl + '%22/ehg62mqqm%22',
|
||||
});
|
||||
list = response.data.list.slice(0, 20).map((item) => ({
|
||||
link: `${rootUrl}/article/${item.aid}`,
|
||||
}));
|
||||
break;
|
||||
}
|
||||
case 'news-comment': {
|
||||
title = '本报时评';
|
||||
response = await got({
|
||||
method: 'get',
|
||||
url: apiUrl + '%22/egv8vnjpq/egv8vtbcl%22',
|
||||
});
|
||||
list = response.data.list.slice(0, 20).map((item) => ({
|
||||
link: `${rootUrl}/article/${item.aid}`,
|
||||
}));
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
title = $('title').text();
|
||||
|
||||
$('.oPBlock').remove();
|
||||
|
||||
list = $('.list-block ul li, .firstCon-r ul li')
|
||||
.find('a')
|
||||
.slice(0, 10)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
link: `https:${item.attr('href')}`,
|
||||
};
|
||||
})
|
||||
.get();
|
||||
}
|
||||
}
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
try {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content('article').html();
|
||||
item.title = content('.container-title').text();
|
||||
item.author = content('.source').text().replace('来源:', '');
|
||||
item.pubDate = new Date(parseInt(detailResponse.data.match(/\\"ctime\\":(.*),\\"utime\\"/)[1])).toUTCString();
|
||||
|
||||
return item;
|
||||
} catch (e) {
|
||||
return Promise.resolve('');
|
||||
}
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${title} - 生命时报`,
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue