feat: add makeuseof (#6253)
This commit is contained in:
parent
49e49af462
commit
5badeb2137
|
|
@ -115,6 +115,10 @@ Provides a better reading experience (full text articles) over the official one.
|
|||
|
||||
<RouteEn author="loganrockmore" example="/letterboxd/user/followingdiary/demiadejuyigbe" path="/letterboxd/user/followingdiary/:username" :paramsDesc="['username']" />
|
||||
|
||||
## MakeUseOf
|
||||
|
||||
<RouteEn author="nczitzk" example="/makeuseof" path="/makeuseof/:category?" :paramsDesc="['Category, Trending by default']"/>
|
||||
|
||||
## Matters
|
||||
|
||||
### Latest
|
||||
|
|
|
|||
|
|
@ -308,6 +308,10 @@ Tag
|
|||
|
||||
<Route author="loganrockmore" example="/letterboxd/user/followingdiary/demiadejuyigbe" path="/letterboxd/user/followingdiary/:username" :paramsDesc="['username']" />
|
||||
|
||||
## MakeUseOf
|
||||
|
||||
<Route author="nczitzk" example="/makeuseof" path="/makeuseof/:category?" :paramsDesc="['分类,默认为 Trending']"/>
|
||||
|
||||
## Matataki
|
||||
|
||||
::: tip 提示
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue