feat(route): add Odaily星球日报活动 (#7666)
This commit is contained in:
parent
db9460cd8e
commit
490c184389
|
|
@ -567,6 +567,12 @@ IPFS 网关有可能失效,那时候换成其他网关。
|
|||
|
||||
<Route author="emdoe" example="/nautilus/topic/Art" path="/nautilus/topic/:tid" :paramsDesc="['话题 id, 可在页面上方 TOPICS 栏目处找到']"/>
|
||||
|
||||
## Odaily 星球日报
|
||||
|
||||
### 活动
|
||||
|
||||
<Route author="ncziztk" example="/odaily/activity" path="/odaily/activity"/>
|
||||
|
||||
## OpenAI
|
||||
|
||||
### Blog
|
||||
|
|
|
|||
|
|
@ -4221,4 +4221,7 @@ router.get('/questmobile/report/:category?/:label?', require('./routes/questmobi
|
|||
// RSS3
|
||||
router.get('/rss3/blog', require('./routes/rss3/blog'));
|
||||
|
||||
// 星球日报
|
||||
router.get('/odaily/activity', require('./routes/odaily/activity'));
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const timezone = require('@/utils/timezone');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const rootUrl = 'https://www.odaily.com';
|
||||
const currentUrl = `${rootUrl}/service/scheme/group/8?page=1&per_page=10`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const list = response.data.data.items.data.map((item) => ({
|
||||
title: item.title,
|
||||
link: `${rootUrl}/activity/${item.id}`,
|
||||
pubDate: timezone(new Date(item.published_at), +8),
|
||||
}));
|
||||
|
||||
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.match(/"content":"(.*)"}},"secondaryList":/)[1]);
|
||||
|
||||
content('img').each(function () {
|
||||
content(this).attr('src', content(this).attr('src').replace(/\\"/g, ''));
|
||||
});
|
||||
|
||||
item.description = content.html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '活动 - Odaily星球日报',
|
||||
link: `${rootUrl}/activityPage`,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue