diff --git a/docs/new-media.md b/docs/new-media.md index 2216b5f86b..b2e1034807 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -567,6 +567,12 @@ IPFS 网关有可能失效,那时候换成其他网关。 +## Odaily 星球日报 + +### 活动 + + + ## OpenAI ### Blog diff --git a/lib/router.js b/lib/router.js index 804b09c362..5e6dc9b497 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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; diff --git a/lib/routes/odaily/activity.js b/lib/routes/odaily/activity.js new file mode 100644 index 0000000000..7d344a7538 --- /dev/null +++ b/lib/routes/odaily/activity.js @@ -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, + }; +};