diff --git a/docs/new-media.md b/docs/new-media.md index 1952e67ad..e0db8a10a 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -4373,6 +4373,16 @@ wechat-feeds 来源[已停止更新](https://github.com/hellodword/wechat-feeds/ +## 知园 + +### Newsletter + + + +### 笔记 + + + ## 中国纺织经济信息网 ### 资讯 diff --git a/lib/v2/zhiy/letter.js b/lib/v2/zhiy/letter.js new file mode 100644 index 000000000..1742b2309 --- /dev/null +++ b/lib/v2/zhiy/letter.js @@ -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, + }; +}; diff --git a/lib/v2/zhiy/maintainer.js b/lib/v2/zhiy/maintainer.js new file mode 100644 index 000000000..f47ce0515 --- /dev/null +++ b/lib/v2/zhiy/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/letters/:author': ['TonyRL'], + '/posts/:author': ['TonyRL'], +}; diff --git a/lib/v2/zhiy/post.js b/lib/v2/zhiy/post.js new file mode 100644 index 000000000..e1c2294af --- /dev/null +++ b/lib/v2/zhiy/post.js @@ -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, + }; +}; diff --git a/lib/v2/zhiy/radar.js b/lib/v2/zhiy/radar.js new file mode 100644 index 000000000..ed61c28df --- /dev/null +++ b/lib/v2/zhiy/radar.js @@ -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', + }, + ], + }, +}; diff --git a/lib/v2/zhiy/router.js b/lib/v2/zhiy/router.js new file mode 100644 index 000000000..69d4d9748 --- /dev/null +++ b/lib/v2/zhiy/router.js @@ -0,0 +1,4 @@ +module.exports = (router) => { + router.get('/letters/:author', require('./letter')); + router.get('/posts/:author', require('./post')); +}; diff --git a/lib/v2/zhiy/templates/post.art b/lib/v2/zhiy/templates/post.art new file mode 100644 index 000000000..a69d68110 --- /dev/null +++ b/lib/v2/zhiy/templates/post.art @@ -0,0 +1,12 @@ +{{ postMeta.visit_amount }}阅读 {{ postMeta.note_amount }}条笔记 创建于{{ postDate }} +
+{{ each posts post }} + {{ each post.struct.items item }} + {{ if item.type === 'text' }}{{@ item.content.replace(/\n/g, '
') }}
{{ /if }} + {{ if item.type === 'url' }}{{ item.content }}{{ /if }} + {{ if item.type === 'link' }}{{@ item.content.replace(/\n/g, '
') }}
{{ /if }} + {{ /each }} +
+{{ dayjs(post.publish_time_timestamp, 'X').format('YYYY-MM-DD HH:mm:ss') }} +
+{{ /each }} diff --git a/lib/v2/zhiy/utils.js b/lib/v2/zhiy/utils.js new file mode 100644 index 000000000..5cc0100d3 --- /dev/null +++ b/lib/v2/zhiy/utils.js @@ -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, +};