Skip to content

Commit

Permalink
feat(route): add VCB-Studio (DIYgod#12074)
Browse files Browse the repository at this point in the history
* feat(route): add VCB-Studio

* feat(route): VCB-Studio change to use WordPress API

* feat(route): VCB-Studio use art-template

* fix: typo

---------
  • Loading branch information
cxfksword authored Mar 11, 2023
1 parent 09b249a commit 4b84b0d
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/anime.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 51 additions & 0 deletions lib/v2/vcb-s/category.js
Original file line number Diff line number Diff line change
@@ -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,
};
};
39 changes: 39 additions & 0 deletions lib/v2/vcb-s/index.js
Original file line number Diff line number Diff line change
@@ -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,
};
};
4 changes: 4 additions & 0 deletions lib/v2/vcb-s/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
'/': ['cxfksword'],
'/category/:cate': ['cxfksword'],
};
19 changes: 19 additions & 0 deletions lib/v2/vcb-s/radar.js
Original file line number Diff line number Diff line change
@@ -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',
},
],
},
};
4 changes: 4 additions & 0 deletions lib/v2/vcb-s/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = (router) => {
router.get('/', require('./index'));
router.get('/category/:cate', require('./category'));
};
9 changes: 9 additions & 0 deletions lib/v2/vcb-s/templates/post.art
Original file line number Diff line number Diff line change
@@ -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 }}

0 comments on commit 4b84b0d

Please sign in to comment.