fix: psnine news (#6536)
This commit is contained in:
parent
26a8a59558
commit
bbb4e4d25c
31
docs/game.md
31
docs/game.md
|
|
@ -269,16 +269,37 @@ pageClass: routes
|
|||
|
||||
<Route author="LightStrawberry" example="/psnine/index" path="/psnine/index"/>
|
||||
|
||||
### 新闻 - 游戏资讯
|
||||
### 节点
|
||||
|
||||
<Route author="LightStrawberry" example="/psnine/news" path="/psnine/news"/>
|
||||
### 数折-折扣信息推送
|
||||
<Route author="nczitzk" example="/psnine/node/news" path="/psnine/node/:id?/:order?" :paramsDesc="['节点 id,见下表,默认为 news', '排序,可选 `date` 即最新,默认为 `obdate` 即综合排序']">
|
||||
|
||||
| 站务 | 活动 | 旅记 | 折扣 | 会免 |
|
||||
| ---- | ----- | ------ | ---- | ---- |
|
||||
| p9 | event | travel | off | plus |
|
||||
|
||||
| 新闻 | 攻略 | 测评 | 心得 | 开箱 |
|
||||
| ---- | ----- | ------ | ---- | ------- |
|
||||
| news | guide | review | exp | openbox |
|
||||
|
||||
| 游列 | 游计 | Ps4 | Ps5 |
|
||||
| -------- | -------- | --- | --- |
|
||||
| gamelist | planlist | ps4 | ps5 |
|
||||
|
||||
| 发米通 | Ign | Ucg |
|
||||
| ------- | --- | --- |
|
||||
| famitsu | ign | ucg |
|
||||
|
||||
</Route>
|
||||
|
||||
### 数折 - 折扣信息推送
|
||||
|
||||
<Route author="LightStrawberry" example="/psnine/shuzhe" path="/psnine/shuzhe"/>
|
||||
### 闲游-二手盘信息
|
||||
|
||||
### 闲游 - 二手盘信息
|
||||
|
||||
<Route author="LightStrawberry" example="/psnine/trade" path="/psnine/trade"/>
|
||||
### 游戏-新游戏奖杯信息
|
||||
|
||||
### 游戏 - 新游戏奖杯信息
|
||||
|
||||
<Route author="LightStrawberry" example="/psnine/game" path="/psnine/game"/>
|
||||
|
||||
|
|
|
|||
|
|
@ -1554,7 +1554,8 @@ router.get('/psnine/index', require('./routes/psnine/index'));
|
|||
router.get('/psnine/shuzhe', require('./routes/psnine/shuzhe'));
|
||||
router.get('/psnine/trade', require('./routes/psnine/trade'));
|
||||
router.get('/psnine/game', require('./routes/psnine/game'));
|
||||
router.get('/psnine/news', require('./routes/psnine/news'));
|
||||
router.get('/psnine/news/:order?', require('./routes/psnine/news'));
|
||||
router.get('/psnine/node/:id?/:order?', require('./routes/psnine/node'));
|
||||
|
||||
// 浙江大学
|
||||
router.get('/zju/list/:type', require('./routes/universities/zju/list'));
|
||||
|
|
|
|||
|
|
@ -1,32 +1,54 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const date = require('@/utils/date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const url = 'https://www.psnine.com/news';
|
||||
const order = ctx.params.order || 'obdate';
|
||||
|
||||
const rootUrl = 'https://www.psnine.com';
|
||||
const currentUrl = `${rootUrl}/node/news?ob=${order}`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: url,
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const data = response.data;
|
||||
const $ = cheerio.load(data);
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const out = $('.box li')
|
||||
.map(function () {
|
||||
const info = {
|
||||
title: $(this).find('.content').text(),
|
||||
link: $(this).find('.touch').attr('href'),
|
||||
pubDate: date($(this).find('.meta').text()),
|
||||
author: $(this).find('.meta a').text(),
|
||||
$('.psnnode, .node').remove();
|
||||
|
||||
const list = $('.title a')
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
const date = item.parent().next().text().trim();
|
||||
|
||||
return {
|
||||
title: item.text(),
|
||||
link: item.attr('href'),
|
||||
pubDate: new Date(date.length === 11 ? `${new Date().getFullYear()}-${date}` : date).toUTCString(),
|
||||
};
|
||||
return info;
|
||||
})
|
||||
.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.author = content('a[itemprop="author"]').eq(0).text();
|
||||
item.description = content('div[itemprop="articleBody"]').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: 'psnine-' + $('title').text(),
|
||||
link: 'https://www.psnine.com/',
|
||||
item: out,
|
||||
title: `${$('title').text()} - PSN中文站`,
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id || 'news';
|
||||
const order = ctx.params.order || 'obdate';
|
||||
|
||||
const rootUrl = 'https://www.psnine.com';
|
||||
const currentUrl = `${rootUrl}/node/${id}?ob=${order}`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
$('.psnnode, .node').remove();
|
||||
|
||||
const list = $('.title a')
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
const date = item.parent().next().text().trim();
|
||||
|
||||
return {
|
||||
title: item.text(),
|
||||
link: item.attr('href'),
|
||||
pubDate: new Date(date.length === 11 ? `${new Date().getFullYear()}-${date}` : date).toUTCString(),
|
||||
};
|
||||
})
|
||||
.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.author = content('a[itemprop="author"]').eq(0).text();
|
||||
item.description = content('div[itemprop="articleBody"]').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${$('title').text()} - PSN中文站`,
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue