feat(route): add VCB-Studio (#12074)
* feat(route): add VCB-Studio * feat(route): VCB-Studio change to use WordPress API * feat(route): VCB-Studio use art-template * fix: typo ---------
This commit is contained in:
parent
09b249a4cd
commit
4b84b0dbd7
|
|
@ -436,6 +436,22 @@ Sources
|
|||
|
||||
<Route author="aether17" path="/thwiki/calendar/:before?/:after?" example="/thwiki/calendar" :paramsDesc="['从多少天前(默认30)', '到多少天后(默认30)']" radar="1" rssbud="1"/>
|
||||
|
||||
## VCB-Studio
|
||||
|
||||
### 最新文章
|
||||
|
||||
<Route author="cxfksword" example="/vcb-s" path="/vcb-s" radar="1"/>
|
||||
|
||||
### 分类文章
|
||||
|
||||
<Route author="cxfksword" example="/vcb-s/category/works" path="/vcb-s/category/:cate" :paramsDesc="['分类']" radar="1">
|
||||
|
||||
| 作品项目 | 科普系列 | 计划与日志 |
|
||||
| ----- | ---- | ------- |
|
||||
| works | kb | planlog |
|
||||
|
||||
</Route>
|
||||
|
||||
## Vol.moe
|
||||
|
||||
### vol
|
||||
|
|
|
|||
|
|
@ -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 class="js-medie-info-detail.*?>(.*?)<\/pre>/gs, '<pre><code>$1</code></pre>').replace(/<div.+?dw-box-download.+?>(.*?)<\/div>/gs, '<pre>$1</pre>'),
|
||||
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: `${category.name} | VCB-Studio`,
|
||||
link: `${rootUrl}/archives/category/${category.slug}`,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
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 postsAPIUrl = `${rootUrl}/wp-json/wp/v2/posts`;
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const limit = ctx.query.limit ?? 7;
|
||||
const url = `${postsAPIUrl}?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 class="js-medie-info-detail.*?>(.*?)<\/pre>/gs, '<pre><code>$1</code></pre>').replace(/<div.+?dw-box-download.+?>(.*?)<\/div>/gs, '<pre>$1</pre>'),
|
||||
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,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
module.exports = {
|
||||
'/': ['cxfksword'],
|
||||
'/category/:cate': ['cxfksword'],
|
||||
};
|
||||
|
|
@ -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',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
module.exports = (router) => {
|
||||
router.get('/', require('./index'));
|
||||
router.get('/category/:cate', require('./category'));
|
||||
};
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
{{ if medias }}
|
||||
{{ each medias media }}
|
||||
<figure class="thumbnail"><img width="{{@ media.media_details.width }}" height="{{@ media.media_details.height }}" src="{{@ media.source_url }}"></figure>
|
||||
{{ /each }}
|
||||
{{ /if }}
|
||||
{{ if post }}
|
||||
{{@ post }}
|
||||
{{ /if }}
|
||||
Loading…
Reference in New Issue