From 9be1b1ea03fa884a8c2db895861e119dd94769e2 Mon Sep 17 00:00:00 2001
From: Hengyu <76626546+5upernova-heng@users.noreply.github.com>
Date: Sun, 9 Apr 2023 22:07:42 +0800
Subject: [PATCH] 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
---------
---
docs/blog.md | 6 +++++
docs/en/blog.md | 6 +++++
lib/v2/macmenubar/maintainer.js | 3 +++
lib/v2/macmenubar/radar.js | 13 +++++++++
lib/v2/macmenubar/recently.js | 47 +++++++++++++++++++++++++++++++++
lib/v2/macmenubar/router.js | 3 +++
6 files changed, 78 insertions(+)
create mode 100644 lib/v2/macmenubar/maintainer.js
create mode 100644 lib/v2/macmenubar/radar.js
create mode 100644 lib/v2/macmenubar/recently.js
create mode 100644 lib/v2/macmenubar/router.js
diff --git a/docs/blog.md b/docs/blog.md
index 84b70d750..8159c0756 100644
--- a/docs/blog.md
+++ b/docs/blog.md
@@ -128,6 +128,12 @@ username 为博主用户名,而非`xxx.hashnode.dev`中`xxx`所代表的 blog
+## MacMenuBar
+
+### Recently
+
+
+
## Paul Graham 博客
通过提取文章全文,提供比官方源更佳的阅读体验。
diff --git a/docs/en/blog.md b/docs/en/blog.md
index 0f4a201bf..5568b6a15 100644
--- a/docs/en/blog.md
+++ b/docs/en/blog.md
@@ -64,6 +64,12 @@ pageClass: routes
+## MacMenuBar
+
+### Recently
+
+
+
## Miris Whispers
### Blog
diff --git a/lib/v2/macmenubar/maintainer.js b/lib/v2/macmenubar/maintainer.js
new file mode 100644
index 000000000..ea484dbcd
--- /dev/null
+++ b/lib/v2/macmenubar/maintainer.js
@@ -0,0 +1,3 @@
+module.exports = {
+ '/recently/:category?': ['5upernova-heng'],
+};
diff --git a/lib/v2/macmenubar/radar.js b/lib/v2/macmenubar/radar.js
new file mode 100644
index 000000000..4672225d4
--- /dev/null
+++ b/lib/v2/macmenubar/radar.js
@@ -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',
+ },
+ ],
+ },
+};
diff --git a/lib/v2/macmenubar/recently.js b/lib/v2/macmenubar/recently.js
new file mode 100644
index 000000000..23c493662
--- /dev/null
+++ b/lib/v2/macmenubar/recently.js
@@ -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,
+ };
+};
diff --git a/lib/v2/macmenubar/router.js b/lib/v2/macmenubar/router.js
new file mode 100644
index 000000000..80950a071
--- /dev/null
+++ b/lib/v2/macmenubar/router.js
@@ -0,0 +1,3 @@
+module.exports = (router) => {
+ router.get('/recently/:category?', require('./recently'));
+};