feat(route): zhiy (#11654)

This commit is contained in:
Tony
2023-01-19 19:03:31 -03:00
committed by GitHub
parent a3bd12171f
commit ddf82784ec
8 changed files with 165 additions and 0 deletions
+10
View File
@@ -4373,6 +4373,16 @@ wechat-feeds 来源[已停止更新](https://github.com/hellodword/wechat-feeds/
<Route author="x2009again" example="/yunspe/newsflash" path="/yunspe/newsflash" />
## 知园
### Newsletter
<Route author="TonyRL" example="/zhiy/letters/messy" path="/zhiy/letters/:author" :paramsDesc="['作者 ID,可在URL中找到']" radar="1" rssbud="1"/>
### 笔记
<Route author="TonyRL" example="/zhiy/posts/long" path="/zhiy/posts/:author" :paramsDesc="['作者 ID,可在URL中找到']" radar="1" rssbud="1"/>
## 中国纺织经济信息网
### 资讯
+34
View File
@@ -0,0 +1,34 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const { baseUrl, fetchUserDate } = require('./utils');
module.exports = async (ctx) => {
const { author } = ctx.params;
const userData = await fetchUserDate(author);
const { author_id: authorId } = userData;
const {
data: { result: letters },
} = await got(`${baseUrl}/api/app/users/${authorId}/letters`, {
searchParams: {
page: 1,
limit: ctx.query.limit ? parseInt(ctx.query.limit) : 100,
},
});
const items = letters.map((item) => ({
title: item.title,
description: item.shortcut,
pubDate: parseDate(item.send_time, 'X'),
link: `${baseUrl}/letter/${item.id}`,
}));
ctx.state.data = {
title: userData.author_name,
link: `${baseUrl}/${author}`,
description: userData.author_signature,
image: userData.author_avatar_url,
item: items,
};
};
+4
View File
@@ -0,0 +1,4 @@
module.exports = {
'/letters/:author': ['TonyRL'],
'/posts/:author': ['TonyRL'],
};
+69
View File
@@ -0,0 +1,69 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const { baseUrl, fetchUserDate } = require('./utils');
const { art } = require('@/utils/render');
const path = require('path');
const dayjs = require('dayjs');
module.exports = async (ctx) => {
art.defaults.imports = {
dayjs,
...art.defaults.imports,
};
const { author } = ctx.params;
const userData = await fetchUserDate(author);
const { author_id: authorId } = userData;
const {
data: { result: posts },
} = await got(`${baseUrl}/api/app/share/garden/users/${authorId}/posts`, {
searchParams: {
page: 1,
limit: ctx.query.limit ? parseInt(ctx.query.limit) : 100,
},
});
const list = posts.map((item) => ({
title: item.title,
pubDate: parseDate(item.create_time, 'X'),
link: `${baseUrl}/b${item.share_md5}`,
guid: `${baseUrl}/b${item.share_md5}:${item.link_amount}:${item.note_amount}`,
postId: item.id,
shareMD5: item.share_md5,
}));
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: postMeta } = await got(`${baseUrl}/api/app/share/posts/${item.shareMD5}`);
const {
data: { result: posts },
} = await got(`${baseUrl}/api/app/share/posts/${item.postId}/notes`, {
searchParams: {
page: 1,
limit: 100,
},
});
item.description = art(path.join(__dirname, 'templates/post.art'), {
postMeta,
postDate: dayjs(postMeta.create_time, 'X').format('YYYY-MM-DD HH:mm:ss'),
posts,
});
return item;
})
)
);
ctx.state.data = {
title: userData.author_name,
link: `${baseUrl}/${author}`,
description: userData.author_signature,
image: userData.author_avatar_url,
item: items,
};
};
+19
View File
@@ -0,0 +1,19 @@
module.exports = {
'zhiy.cc': {
_name: '知园',
'.': [
{
title: 'Newsletter',
docs: 'https://docs.rsshub.app/new-media.html#zhi-yuan',
source: ['/:author'],
target: '/zhiy/letters/:author',
},
{
title: '笔记',
docs: 'https://docs.rsshub.app/new-media.html#zhi-yuan',
source: ['/:author'],
target: '/zhiy/posts/:author',
},
],
},
};
+4
View File
@@ -0,0 +1,4 @@
module.exports = (router) => {
router.get('/letters/:author', require('./letter'));
router.get('/posts/:author', require('./post'));
};
+12
View File
@@ -0,0 +1,12 @@
{{ postMeta.visit_amount }}阅读 {{ postMeta.note_amount }}条笔记 创建于{{ postDate }}
<br>
{{ each posts post }}
{{ each post.struct.items item }}
{{ if item.type === 'text' }}<span>{{@ item.content.replace(/\n/g, '<br>') }}</span>{{ /if }}
{{ if item.type === 'url' }}<a href="{{ item.url }}">{{ item.content }}</a>{{ /if }}
{{ if item.type === 'link' }}<span>{{@ item.content.replace(/\n/g, '<br>') }}</span>{{ /if }}
{{ /each }}
<br>
{{ dayjs(post.publish_time_timestamp, 'X').format('YYYY-MM-DD HH:mm:ss') }}
<hr>
{{ /each }}
+13
View File
@@ -0,0 +1,13 @@
const got = require('@/utils/got');
const baseUrl = 'https://zhiy.cc';
const fetchUserDate = async (author) => {
const { data: userData } = await got(`${baseUrl}/api/app/share/garden/users/${author}`);
return userData;
};
module.exports = {
baseUrl,
fetchUserDate,
};