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:
parent
7d4e7e594f
commit
9be1b1ea03
|
|
@ -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 博客
|
||||
|
||||
通过提取文章全文,提供比官方源更佳的阅读体验。
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/recently/:category?': ['5upernova-heng'],
|
||||
};
|
||||
|
|
@ -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',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = (router) => {
|
||||
router.get('/recently/:category?', require('./recently'));
|
||||
};
|
||||
Loading…
Reference in New Issue