feat(route): add Macfilos Blog (#10571)
* feat(route): add Macfilos Blog * docs: add en
This commit is contained in:
@@ -468,6 +468,12 @@ Edition
|
||||
|
||||
</RouteEn>
|
||||
|
||||
## Macfilos
|
||||
|
||||
### Blog
|
||||
|
||||
<RouteEn author="nczitzk" example="/macfilos/blog" path="/macfilos/blog" />
|
||||
|
||||
## MakeUseOf
|
||||
|
||||
<RouteEn author="nczitzk" example="/makeuseof" path="/makeuseof/:category?" :paramsDesc="['Category, Trending by default']"/>
|
||||
|
||||
@@ -801,6 +801,12 @@ Edition
|
||||
|
||||
</Route>
|
||||
|
||||
## Macfilos
|
||||
|
||||
### Blog
|
||||
|
||||
<Route author="nczitzk" example="/macfilos/blog" path="/macfilos/blog" />
|
||||
|
||||
## MakeUseOf
|
||||
|
||||
<Route author="nczitzk" example="/makeuseof" path="/makeuseof/:category?" :paramsDesc="['分类,默认为 Trending']"/>
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const rootUrl = 'https://www.macfilos.com';
|
||||
const currentUrl = `${rootUrl}/blog`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
let items = $('.entry-title a')
|
||||
.slice(0, ctx.query.limit ? parseInt(ctx.query.limit) : 10)
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
|
||||
const parent = item.parent().parent();
|
||||
|
||||
return {
|
||||
title: item.text(),
|
||||
link: item.attr('href'),
|
||||
author: parent.find('.td-post-author-name a').text(),
|
||||
pubDate: parseDate(parent.find('.td-post-date time').attr('datetime')),
|
||||
};
|
||||
});
|
||||
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
content('hr').nextAll().remove();
|
||||
content('hr').remove();
|
||||
|
||||
content('img').each(function () {
|
||||
content(this).removeAttr('srcset');
|
||||
});
|
||||
|
||||
item.description = content('.td-post-content').html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/blog': ['nczitzk'],
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
'macfilos.com': {
|
||||
_name: 'Macfilos',
|
||||
'.': [
|
||||
{
|
||||
title: 'Blog',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#macfilos-blog',
|
||||
source: ['/blog', '/'],
|
||||
target: '/macfilos/blog',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/blog', require('./blog'));
|
||||
};
|
||||
Reference in New Issue
Block a user