forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add VCB-Studio (DIYgod#12074)
* 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
Showing
7 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
'/': ['cxfksword'], | ||
'/category/:cate': ['cxfksword'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |