feat(route): add MacMenuBar (#12258)

* feat(route): MacMenuBar

* Update: Change to WordPress API; Combine two routes together; Move related documentation to blog.md

* Fix: add maintainer.js

* Update: filter categories by API; support multiple categories

* Update lib/v2/macmenubar/recently.js

* Update: update rss link; fix doc

---------
This commit is contained in:
Hengyu 2023-04-09 22:07:42 +08:00 committed by GitHub
parent 7d4e7e594f
commit 9be1b1ea03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 78 additions and 0 deletions

View File

@ -128,6 +128,12 @@ username 为博主用户名,而非`xxx.hashnode.dev`中`xxx`所代表的 blog
<Route author="chazeon" example="/miris/blog" path="/miris/blog" />
## MacMenuBar
### Recently
<RouteEn author="5upernova-heng" example="/macmenubar/recently/developer-apps,system-tools" path="/macmenubar/recently/:category?" :paramsDesc="['分类名,多个使用逗号隔开,留空则为全部。分类名可在 URL 中找到']" radar="1" />
## Paul Graham 博客
通过提取文章全文,提供比官方源更佳的阅读体验。

View File

@ -64,6 +64,12 @@ pageClass: routes
<RouteEn author="james-tindal" example="/ash-maurya" path="/ash-maurya"/>
## MacMenuBar
### Recently
<RouteEn author="5upernova-heng" example="/macmenubar/recently/developer-apps,system-tools" path="/macmenubar/recently/:category?" :paramsDesc="['Category path name, seperate by comma, default is all categories. Category path name can be found in url']" radar="1" />
## Miris Whispers
### Blog

View File

@ -0,0 +1,3 @@
module.exports = {
'/recently/:category?': ['5upernova-heng'],
};

View File

@ -0,0 +1,13 @@
module.exports = {
'macmenubar.com': {
_name: 'MacMenuBar',
'.': [
{
title: 'Recently Added',
docs: 'https://docs.rsshub.app/other.html#macmenubar',
source: ['/recently-added', '/:category'],
target: '/macmenubar/recently/category',
},
],
},
};

View File

@ -0,0 +1,47 @@
const got = require('@/utils/got');
async function getCategoryId(categories) {
const baseUrl = `https://macmenubar.com/wp-json/wp/v2/categories`;
const { data: response } = await got(baseUrl, {
method: 'GET',
searchParams: {
slug: categories,
},
});
return response.reduce((queryString, item) => queryString + item.id + ',', '');
}
module.exports = async (ctx) => {
const baseUrl = 'https://macmenubar.com/wp-json/wp/v2/posts';
const categories = ctx.params.category;
const searchParams = {
per_page: 100,
};
if (categories) {
searchParams.categories = await getCategoryId(categories);
}
const response = await got(baseUrl, {
method: 'GET',
searchParams,
});
const items = response.data.map((post) => {
const title = post.title.rendered;
const link = post.link;
const pubDate = post.date_gmt;
const description = post.content.rendered;
const tags = post.tag_info.map((tag) => tag.name);
const categories = post.category_info.map((category) => category.name);
return {
title,
link,
pubDate,
description,
category: tags.concat(categories),
};
});
ctx.state.data = {
title: 'Recent Posts | MacMenuBar.com',
link: 'https://macmenubar.com/recently-added/',
item: items,
};
};

View File

@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/recently/:category?', require('./recently'));
};