diff --git a/docs/new-media.md b/docs/new-media.md index 7b31c6612..04f0fa83c 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -4628,6 +4628,16 @@ QueryString: +## 字节点击 + +### 首页 + + + +### 标签 + + + ## 自由微信 ### 公众号 diff --git a/lib/v2/byteclicks/index.js b/lib/v2/byteclicks/index.js new file mode 100644 index 000000000..7eba0d07f --- /dev/null +++ b/lib/v2/byteclicks/index.js @@ -0,0 +1,22 @@ +const got = require('@/utils/got'); +const { parseItem } = require('./utils'); +const baseUrl = 'https://byteclicks.com'; + +module.exports = async (ctx) => { + const { data } = await got(`${baseUrl}/wp-json/wp/v2/posts`, { + searchParams: { + per_page: ctx.query.limit ? parseInt(ctx.query.limit) : 100, + }, + }); + + const items = parseItem(data); + + ctx.state.data = { + title: '字节点击 - 聚合全球优质资源,跟踪世界前沿科技', + description: + 'byteclicks.com 最专业的前沿科技网站。聚合全球优质资源,跟踪世界前沿科技,精选推荐一些很棒的互联网好资源好工具好产品。寻找有前景好项目、找论文、找报告、找数据、找课程、找电子书上byteclicks!byteclicks.com是投资人、科研学者、学生每天必看的网站。', + image: 'https://byteclicks.com/wp-content/themes/RK-Blogger/images/wbolt.ico', + link: baseUrl, + item: items, + }; +}; diff --git a/lib/v2/byteclicks/maintainer.js b/lib/v2/byteclicks/maintainer.js new file mode 100644 index 000000000..065da52e5 --- /dev/null +++ b/lib/v2/byteclicks/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/': ['TonyRL'], + '/tag/:tag': ['TonyRL'], +}; diff --git a/lib/v2/byteclicks/radar.js b/lib/v2/byteclicks/radar.js new file mode 100644 index 000000000..d4360c562 --- /dev/null +++ b/lib/v2/byteclicks/radar.js @@ -0,0 +1,19 @@ +module.exports = { + 'byteclicks.com': { + _name: '字节点击', + '.': [ + { + title: '首页', + docs: 'https://docs.rsshub.app/new-media.html#zi-jie-dian-ji', + source: ['/'], + target: '/byteclicks', + }, + { + title: '标签', + docs: 'https://docs.rsshub.app/new-media.html#zi-jie-dian-ji', + source: ['/tag/:tag'], + target: '/byteclicks/tag/:tag', + }, + ], + }, +}; diff --git a/lib/v2/byteclicks/router.js b/lib/v2/byteclicks/router.js new file mode 100644 index 000000000..8507ca4ac --- /dev/null +++ b/lib/v2/byteclicks/router.js @@ -0,0 +1,4 @@ +module.exports = (router) => { + router.get('/', require('./index')); + router.get('/tag/:tag', require('./tag')); +}; diff --git a/lib/v2/byteclicks/tag.js b/lib/v2/byteclicks/tag.js new file mode 100644 index 000000000..f2957f4e1 --- /dev/null +++ b/lib/v2/byteclicks/tag.js @@ -0,0 +1,30 @@ +const got = require('@/utils/got'); +const { parseItem } = require('./utils'); +const baseUrl = 'https://byteclicks.com'; + +module.exports = async (ctx) => { + const { tag } = ctx.params; + const { data: search } = await got(`${baseUrl}/wp-json/wp/v2/tags`, { + searchParams: { + search: tag, + per_page: 100, + }, + }); + const tagData = search.find((item) => item.name === tag); + + const { data } = await got(`${baseUrl}/wp-json/wp/v2/posts`, { + searchParams: { + per_page: ctx.query.limit ? parseInt(ctx.query.limit) : 100, + tags: tagData.id, + }, + }); + + const items = parseItem(data); + + ctx.state.data = { + title: `${tagData.name} - 字节点击`, + image: 'https://byteclicks.com/wp-content/themes/RK-Blogger/images/wbolt.ico', + link: tagData.link, + item: items, + }; +}; diff --git a/lib/v2/byteclicks/utils.js b/lib/v2/byteclicks/utils.js new file mode 100644 index 000000000..a728db20a --- /dev/null +++ b/lib/v2/byteclicks/utils.js @@ -0,0 +1,13 @@ +const { parseDate } = require('@/utils/parse-date'); + +const parseItem = (data) => + data.map((item) => ({ + title: item.title.rendered, + description: item.content.rendered, + pubDate: parseDate(item.date_gmt), + link: item.link, + })); + +module.exports = { + parseItem, +};