fix(route): 游戏葡萄获取文章全文 (#7114)
This commit is contained in:
parent
0a973535d4
commit
979bac08be
|
|
@ -2231,16 +2231,15 @@ column 为 third 时可选的 category:
|
|||
|
||||
## 游戏葡萄
|
||||
|
||||
无文章正文,仅有目录索引。
|
||||
### 文章
|
||||
|
||||
### 全部文章
|
||||
<Route author="KotoriK nczitzk" example="/gamegrape/13" path="/gamegrape/:id?" :paramsDesc="['分类 id,见下表,默认为全部']">
|
||||
|
||||
<Route author="KotoriK" example="/gamegrape" path="/gamegrape/index"/>
|
||||
| 全部 | 深度 | 资讯 | DemoWall | 酷玩 | 海外 | 专栏 | 葡萄观察 |
|
||||
| ---- | ---- | ---- | -------- | ---- | ---- | ---- | -------- |
|
||||
| | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
|
||||
|
||||
### 分类
|
||||
|
||||
例子对应[深度分类](http://youxiputao.com/article/index/id/13)
|
||||
<Route author="KotoriK" example="/gamegrape/13" path="/gamegrape/:id?"/>
|
||||
</Route>
|
||||
|
||||
## 鱼塘热榜
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const BASE_URL = 'http://youxiputao.com';
|
||||
|
||||
function getNum(str) {
|
||||
const result = str.match(/(\d{1,2}).*/);
|
||||
if (result) {
|
||||
|
|
@ -21,29 +21,54 @@ function resolveRelativeTime(relativeTime) {
|
|||
}
|
||||
return (((day || 0) * 24 + (hour || 0)) * 60 + (min || 0)) * 60 * 1000;
|
||||
}
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { id } = ctx.params;
|
||||
const feed_url = `${BASE_URL}/article/${id ? `index/id/${id}` : ''}`;
|
||||
const resp = await got({ url: feed_url });
|
||||
const { data } = resp;
|
||||
const $ = cheerio.load(data);
|
||||
const feed_title = $('title').text();
|
||||
const id = ctx.params.id || '';
|
||||
|
||||
const rootUrl = 'http://youxiputao.com';
|
||||
const currentUrl = `${rootUrl}/article${id ? `/index/id/${id}` : ''}`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('.news-info-box')
|
||||
.slice(0, 15)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
const txt_author_pubDate = $(item.find('div > p > span')[1]).text();
|
||||
const a = item.find('a[title]');
|
||||
|
||||
return {
|
||||
title: item.parent().find('h4').text(),
|
||||
link: BASE_URL + item.find('a.cover').attr('href'),
|
||||
author: `${txt_author_pubDate}`.replace(/ · \S*$/, ''),
|
||||
description: $(item.find('div > p')[0]).text(),
|
||||
pubDate: Date.now() - resolveRelativeTime(txt_author_pubDate),
|
||||
title: a.text(),
|
||||
link: `${rootUrl}${a.attr('href')}`,
|
||||
pubDate: Date.now() - resolveRelativeTime(item.find('.pull-right').text()),
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content('.info').html();
|
||||
item.author = content('.users-info h4').text();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: feed_title,
|
||||
link: feed_url,
|
||||
item: list,
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue