feat(route): Add ymgal.games RSS (#11241)
* feat(route): Add 月幕 Galgame RSS * fix(route): improve cache and fix radar path * feat(route): add all type * docs: fix param * fix: sort publishTime
This commit is contained in:
parent
68cf1f2ca0
commit
ba2c3419b6
|
|
@ -711,6 +711,18 @@ Sources
|
|||
|
||||
<Route author="DIYgod kotoyuuko" example="/hhgal" path="/hhgal"/>
|
||||
|
||||
## 月幕 Galgame
|
||||
|
||||
### 文章
|
||||
|
||||
<Route author="SunBK201" example="/ymgal/article" path="/ymgal/article/:type?" :paramsDesc="['文章类型']" radar="1">
|
||||
|
||||
| All | 资讯 | 专栏 |
|
||||
| --- | ---- | ------ |
|
||||
| all | news | column |
|
||||
|
||||
</Route>
|
||||
|
||||
## 终点分享
|
||||
|
||||
### 最新汉化
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
const host = 'https://www.ymgal.games';
|
||||
|
||||
const types = {
|
||||
news: '?type=NEWS&page=1',
|
||||
column: '?type=COLUMN&page=1',
|
||||
};
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const type = ctx.params.type || 'all';
|
||||
|
||||
const link = `${host}/co/topic/list` + types[type];
|
||||
let data = [];
|
||||
if (type === 'all') {
|
||||
await Promise.all(
|
||||
Object.values(types).map(async (type) => {
|
||||
const response = await got(`${host}/co/topic/list${type}`);
|
||||
data.push.apply(data, response.data.data);
|
||||
})
|
||||
);
|
||||
data = data.sort((a, b) => b.publishTime - a.publishTime).slice(0, 10);
|
||||
} else {
|
||||
const response = await got(link);
|
||||
data = response.data.data;
|
||||
}
|
||||
|
||||
const items = await Promise.all(
|
||||
data.map((item) => {
|
||||
const itemUrl = host + '/co/article/' + item.topicId;
|
||||
return ctx.cache.tryGet(itemUrl, async () => {
|
||||
const result = await got(itemUrl);
|
||||
const $ = cheerio.load(result.data);
|
||||
const description = $('article').html().trim();
|
||||
return {
|
||||
title: item.title,
|
||||
link: itemUrl,
|
||||
pubDate: timezone(parseDate(item.publishTime), 8),
|
||||
description,
|
||||
};
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
let info = '全部文章';
|
||||
if (type === 'news') {
|
||||
info = '资讯';
|
||||
} else if (type === 'column') {
|
||||
info = '专栏';
|
||||
}
|
||||
|
||||
ctx.state.data = {
|
||||
title: `月幕 Galgame - ${info}`,
|
||||
link: 'https://www.ymgal.games/co/article',
|
||||
description: `月幕 Galgame - ${info}`,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = {
|
||||
'/article/:type?': ['SunBK201'],
|
||||
};
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
module.exports = {
|
||||
'ymgal.games': {
|
||||
_name: '月幕 Galgame',
|
||||
'.': [
|
||||
{
|
||||
title: '全部文章',
|
||||
docs: 'https://docs.rsshub.app/anime.html#yue-mu-galgame',
|
||||
source: ['/co/article'],
|
||||
target: '/ymgal/article/all',
|
||||
},
|
||||
{
|
||||
title: '资讯',
|
||||
docs: 'https://docs.rsshub.app/anime.html#yue-mu-galgame',
|
||||
source: ['/co/article'],
|
||||
target: '/ymgal/article/news',
|
||||
},
|
||||
{
|
||||
title: '专栏',
|
||||
docs: 'https://docs.rsshub.app/anime.html#yue-mu-galgame',
|
||||
source: ['/co/article'],
|
||||
target: '/ymgal/article/column',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = (router) => {
|
||||
router.get('/article/:type?', require('./article'));
|
||||
};
|
||||
Loading…
Reference in New Issue