diff --git a/docs/anime.md b/docs/anime.md index cfac9ad97..19fb30caa 100644 --- a/docs/anime.md +++ b/docs/anime.md @@ -436,6 +436,22 @@ Sources +## VCB-Studio + +### 最新文章 + + + +### 分类文章 + + + +| 作品项目 | 科普系列 | 计划与日志 | +| ----- | ---- | ------- | +| works | kb | planlog | + + + ## Vol.moe ### vol diff --git a/lib/v2/vcb-s/category.js b/lib/v2/vcb-s/category.js new file mode 100644 index 000000000..68a7d3b4b --- /dev/null +++ b/lib/v2/vcb-s/category.js @@ -0,0 +1,51 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); + +const rootUrl = 'https://vcb-s.com'; +const cateAPIUrl = `${rootUrl}/wp-json/wp/v2/categories`; +const postsAPIUrl = `${rootUrl}/wp-json/wp/v2/posts`; + +module.exports = async (ctx) => { + const cate = ctx.params.cate; + const limit = ctx.query.limit ?? 7; + + const cateUrl = `${cateAPIUrl}?slug=${cate}`; + const category = await ctx.cache.tryGet(cateUrl, async () => { + const res = await got.get(cateUrl); + + if (typeof res.data === 'string') { + res.data = JSON.parse(res.body.trim()); + } + return res.data[0]; + }); + + const url = `${postsAPIUrl}?categories=${category.id}&page=1&per_page=${limit}&_embed`; + const response = await got.get(url); + if (typeof response.data === 'string') { + response.data = JSON.parse(response.body.trim()); + } + const data = response.data; + + const items = data.map((item) => { + const description = art(path.join(__dirname, 'templates/post.art'), { + post: item.content.rendered.replace(/
(.*?)<\/pre>/gs, '
$1
').replace(/(.*?)<\/div>/gs, '
$1
'), + medias: item._embedded['wp:featuredmedia'], + }); + + return { + title: item.title.rendered, + link: item.link, + description, + pubDate: parseDate(item.date_gmt), + author: item._embedded.author[0].name, + }; + }); + + ctx.state.data = { + title: 'VCB-Studio - 大家一起实现的故事!', + link: rootUrl, + item: items, + }; +}; diff --git a/lib/v2/vcb-s/maintainer.js b/lib/v2/vcb-s/maintainer.js new file mode 100644 index 000000000..f23ed6384 --- /dev/null +++ b/lib/v2/vcb-s/maintainer.js @@ -0,0 +1,4 @@ +module.exports = { + '/': ['cxfksword'], + '/category/:cate': ['cxfksword'], +}; diff --git a/lib/v2/vcb-s/radar.js b/lib/v2/vcb-s/radar.js new file mode 100644 index 000000000..3f4f80836 --- /dev/null +++ b/lib/v2/vcb-s/radar.js @@ -0,0 +1,19 @@ +module.exports = { + 'vcb-s.com': { + _name: 'VCB-Studio', + '.': [ + { + title: '最新文章', + docs: 'https://docs.rsshub.app/anime.html#vcb-studio', + source: ['/'], + target: '/vcb-s', + }, + { + title: '分类文章', + docs: 'https://docs.rsshub.app/anime.html#vcb-studio', + source: ['/archives/category/:cate'], + target: '/vcb-s/category/:cate', + }, + ], + }, +}; diff --git a/lib/v2/vcb-s/router.js b/lib/v2/vcb-s/router.js new file mode 100644 index 000000000..18fb0db3d --- /dev/null +++ b/lib/v2/vcb-s/router.js @@ -0,0 +1,4 @@ +module.exports = (router) => { + router.get('/', require('./index')); + router.get('/category/:cate', require('./category')); +}; diff --git a/lib/v2/vcb-s/templates/post.art b/lib/v2/vcb-s/templates/post.art new file mode 100644 index 000000000..2f026e84c --- /dev/null +++ b/lib/v2/vcb-s/templates/post.art @@ -0,0 +1,9 @@ + +{{ if medias }} +{{ each medias media }} +
+{{ /each }} +{{ /if }} +{{ if post }} +{{@ post }} +{{ /if }}