diff --git a/docs/en/new-media.md b/docs/en/new-media.md index b330d8a8a..45a788b37 100644 --- a/docs/en/new-media.md +++ b/docs/en/new-media.md @@ -115,6 +115,10 @@ Provides a better reading experience (full text articles) over the official one. +## MakeUseOf + + + ## Matters ### Latest diff --git a/docs/new-media.md b/docs/new-media.md index 77c1b42d6..04b922aa7 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -308,6 +308,10 @@ Tag +## MakeUseOf + + + ## Matataki ::: tip 提示 diff --git a/lib/router.js b/lib/router.js index d5a18aa9d..17cecdde1 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3513,6 +3513,9 @@ router.get('/uisdc/news', require('./routes/uisdc/news')); router.get('/uisdc/zt/:title?', require('./routes/uisdc/zt')); router.get('/uisdc/topic/:title?/:sort?', require('./routes/uisdc/topic')); +// MakeUseOf +router.get('/makeuseof/:category?', require('./routes/makeuseof/index')); + // 瞬Matataki // 热门作品 router.get('/matataki/posts/hot/:ipfsFlag?', require('./routes/matataki/site/posts/scoreranking')); diff --git a/lib/routes/makeuseof/index.js b/lib/routes/makeuseof/index.js new file mode 100644 index 000000000..fa43b2443 --- /dev/null +++ b/lib/routes/makeuseof/index.js @@ -0,0 +1,60 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const category = ctx.params.category || ''; + + const rootUrl = 'https://www.makeuseof.com'; + const currentUrl = `${rootUrl}${category === '' ? '' : '/category/' + category}`; + const response = await got({ + method: 'get', + url: currentUrl, + }); + + const $ = cheerio.load(response.data); + + const list = $('.home-secondary, .listing-content') + .find('.bc-title-link') + .slice(0, 15) + .map((_, item) => { + item = $(item); + return { + title: item.text(), + link: `${rootUrl}${item.attr('href')}`, + }; + }) + .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); + + content('.img-article-item') + .find('img') + .each(function () { + content(this).attr('src', content(this).prev().attr('data-srcset').split('?')[0]); + }); + + content('.ad-zone-container, .sharing, .sentinel-article-nextArticle, .article-tags, .w-article-author-bio, .ml-form-embedContainer').remove(); + + item.description = content('.article-body').html(); + item.author = content('a.author').text().replace('By ', ''); + item.pubDate = new Date(content('time').attr('datetime')).toUTCString(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `MakeUseOf - ${$('.listing-title').text() ? $('.listing-title').text() : 'Trending'}`, + link: currentUrl, + item: items, + }; +};