feat(route): add route for bluesky post search ("keyword") (#12893)

* add route for bluesky post search ("keyword")

* try and fix up routes

* Apply suggestions from code review
---------
This commit is contained in:
Markus Unterwaditzer
2023-07-28 04:21:31 +02:00
committed by GitHub
parent 354949eb60
commit 6c07fc6d86
6 changed files with 53 additions and 0 deletions
+6
View File
@@ -4,6 +4,12 @@ pageClass: routes
# Social Media
## Bluesky (bsky)
### Keywords
<RouteEn author="untitaker" example="/bsky/keyword/hello" path="/bsky/keyword/:keyword" radar="1" rssbud="1" />
## Crossbell
### Notes
+6
View File
@@ -24,6 +24,12 @@ Tiny Tiny RSS 会给所有 iframe 元素添加 `sandbox="allow-scripts"` 属性
:::
## Bluesky (bsky)
### 关键词
<Route author="untitaker" example="/bsky/keyword/hello" path="/bsky/keyword/:keyword" radar="1" rssbud="1" />
### 番剧
<Route author="DIYgod" example="/bilibili/bangumi/media/9192" path="/bilibili/bangumi/media/:mediaid" :paramsDesc="['番剧媒体 id, 番剧主页 URL 中获取']"/>
+22
View File
@@ -0,0 +1,22 @@
const got = require('@/utils/got');
module.exports = async (ctx) => {
const { keyword } = ctx.params;
const apiLink = `https://search.bsky.social/search/posts?q=${encodeURIComponent(keyword)}`;
const { data } = await got(apiLink);
const items = data.map((item) => ({
title: item.post.text,
link: `https://bsky.app/profile/${item.user.handle}/post/${item.tid.split('/')[1]}`,
description: item.post.text,
pubDate: new Date(item.post.createdAt / 1000000),
author: item.user.handle,
}));
ctx.state.data = {
title: `Bluesky Keyword - ${keyword}`,
link: `https://bsky.app/search?q=${encodeURIComponent(keyword)}`,
item: items,
};
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/keyword/:keyword': ['untitaker'],
};
+13
View File
@@ -0,0 +1,13 @@
module.exports = {
'bsky.app': {
_name: 'Bluesky',
'.': [
{
title: '关键词',
docs: 'https://docs.rsshub.app/social-media.html#bluesky-bsky',
source: '/search',
target: (params, url) => `/bsky/keyword/${new URL(url).searchParams.get('q')}`,
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/keyword/:keyword', require('./keyword'));
};