diff --git a/docs/picture.md b/docs/picture.md index 1011ab900..fd0c44e99 100644 --- a/docs/picture.md +++ b/docs/picture.md @@ -232,3 +232,9 @@ pageClass: routes ### 用户上传作品和用户喜欢作品 + +## 致美化 + +### 最新主题 + + diff --git a/lib/router.js b/lib/router.js index 6cf467481..a0bee8988 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2756,4 +2756,7 @@ router.get('/pbc/tradeAnnouncement', require('./routes/pbc/tradeAnnouncement')); // Monotype router.get('/monotype/article', require('./routes/monotype/article')); +// 致美化 +router.get('/zhutix/latest', require('./routes/zhutix/latest')); + module.exports = router; diff --git a/lib/routes/zhutix/latest.js b/lib/routes/zhutix/latest.js new file mode 100644 index 000000000..90053fc03 --- /dev/null +++ b/lib/routes/zhutix/latest.js @@ -0,0 +1,42 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const currentUrl = 'https://zhutix.com/'; + const response = await got({ + method: 'get', + url: currentUrl, + }); + const $ = cheerio.load(response.data); + const list = $('#main div.grid-bor div.content-card') + .slice(0, 10) + .map((_, item) => { + item = $(item); + const a = item.find('a'); + return { + title: a.text(), + link: a.attr('href'), + pubDate: new Date(item.find('i.feng-liulanjilu').parent().text()).toUTCString(), + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const res = await got({ method: 'get', url: item.link }); + const content = cheerio.load(res.data); + + item.description = content('#entry-content').html(); + return item; + }) + ) + ); + + ctx.state.data = { + title: '致美化 - 最新主题', + link: currentUrl, + item: items, + }; +};