diff --git a/docs/program-update.md b/docs/program-update.md index 1d9a236cde..5cddf1086a 100644 --- a/docs/program-update.md +++ b/docs/program-update.md @@ -413,3 +413,23 @@ pageClass: routes ### 金米奖 + +## 猿料 + +### 标签 + + + +标签 + +| uTools | 插件发布 | +| ------ | -------- | +| utools | plugins | + +排序 + +| 最新回复 | 热门回复 | 新鲜出炉 | 陈年旧贴 | +| -------- | ------------- | ---------- | --------- | +| | -commentCount | -createdAt | createdAt | + + diff --git a/lib/router.js b/lib/router.js index 1612e4b4b3..66d6984b4a 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3767,6 +3767,9 @@ router.get('/sciencenet/blog/:type?/:time?/:sort?', require('./routes/sciencenet // DailyArt router.get('/dailyart/:language?', require('./routes/dailyart/index')); +// 猿料 +router.get('/yuanliao/:tag?/:sort?', require('./routes/yuanliao/index')); + // 中国政协网 router.get('/cppcc/:slug?', require('./routes/gov/cppcc/index')); diff --git a/lib/routes/yuanliao/index.js b/lib/routes/yuanliao/index.js new file mode 100644 index 0000000000..d9333428fa --- /dev/null +++ b/lib/routes/yuanliao/index.js @@ -0,0 +1,43 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const tag = ctx.params.tag || 'utools'; + const sort = ctx.params.sort || ''; + + const rootUrl = 'https://yuanliao.info'; + const currentUrl = `${rootUrl}/api/discussions?tags=${tag}&sort=${sort}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const list = response.data.data.map((item) => ({ + title: item.attributes.title, + link: `${rootUrl}/d/${item.id}-${item.attributes.slug}`, + pubDate: new Date(item.attributes.lastPostedAt).toUTCString(), + })); + + 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('#flarum-content').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${tag} - 猿料`, + link: currentUrl, + item: items, + }; +};