Skip to content

Commit

Permalink
Merge pull request #941 from DIYgod/master
Browse files Browse the repository at this point in the history
[pull] master from diygod:master
  • Loading branch information
pull[bot] authored May 7, 2023
2 parents df3950c + 3450e4c commit a742641
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/game.md
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,18 @@ Example:`https://www.iyingdi.com/tz/people/55547` ,id 是 `55547`

</Route>

### 崩坏:星穹铁道

#### 新闻

<Route author="shinanory" example="/mihoyo/sr" path="/mihoyo/sr/:location?/:category?" :paramsDesc="['区域,可选 `zh-cn`(国服,简中)或 `zh-tw`(国际服,繁中)','分类,见下表,默认为最新']">

| 最新 | 新闻 | 公告 | 活动 |
| -------- | ---- | ------ | -------- |
| news-all | news | notice | activity |

</Route>

## 明日方舟

### 游戏公告与新闻
Expand Down
17 changes: 17 additions & 0 deletions docs/government.md
Original file line number Diff line number Diff line change
Expand Up @@ -1634,3 +1634,20 @@ pageClass: routes
:::

</Route>

## 中央网信办

### 分类

<Route author="drgnchan" example="/gov/cac/xxh" path="/gov/cac/:path+" :paramsDesc="['路径,比如xxh表示信息化']" radar='1'>

::: tip 提示

路径填写对应页面 URL 中间部分。例如:

首页 > 权威发布 > 办公室发布: <http://www.cac.gov.cn/qwfb/bgsfb/A090302index_1.htm>
此时,path 参数为:/qwfb/bgsfb

:::

</Route>
64 changes: 64 additions & 0 deletions lib/v2/gov/cac/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const config = require('@/config').value;

module.exports = async (ctx) => {
const path = ctx.params[0];
const host = 'http://www.cac.gov.cn';
const homepage = `${host}/index.htm`;
// 在首页查找出所有的目录完整路径,比如http://www.cac.gov.cn/xxh/A0906index_1.htm
// xxh --> {"path": "/xxh", "completeUrl": "http://www.cac.gov.cn/xxh/A0906index_1.htm"}
const pathList = await ctx.cache.tryGet(
'gov:cac:pathList',
async () => {
const { data: homepageResponse } = await got(homepage);
const $ = cheerio.load(homepageResponse);
return $('a')
.toArray()
.map((item) => {
const href = $(item).attr('href');
if (href && href.startsWith('http://www.cac.gov.cn/')) {
const matchArray = href.match(/http:\/\/www\.cac\.gov\.cn(.*?)\/(A.*?\.htm)/);
if (matchArray && matchArray.length > 2) {
const path = matchArray[1];
const htmlName = matchArray[2];
return {
path,
completeUrl: `${host}${path}/${htmlName}`,
};
}
}
return null;
})
.filter((item) => item);
},
config.cache.routeExpire,
false
);

const completeUrl = pathList.find((item) => item && item.path === path).completeUrl;
const { data: channelResponse } = await got(completeUrl);
const $1 = cheerio.load(channelResponse);
const items = $1('li.clearfix')
.toArray()
.map((item) => {
const c = $1(item);
const a = c.find('a');
const articleHref = a.attr('href');
const title = a.text();
const date = parseDate(c.find('span.times').text());
return {
link: articleHref,
pubDate: timezone(date),
title,
description: title,
};
});
ctx.state.data = {
title: $1('head title').text(),
link: completeUrl,
item: items,
};
};
1 change: 1 addition & 0 deletions lib/v2/gov/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
// ministry
'/cac/:path+': ['drgnchan'],
'/ccdi/:path+': ['bigfei'],
'/cmse/xwzx/zhxw': ['nczitzk'],
'/cmse/xwzx/yzjz': ['nczitzk'],
Expand Down
11 changes: 11 additions & 0 deletions lib/v2/gov/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,17 @@ module.exports = {
},
],
},
'cac.gov.cn': {
_name: '中央网信办',
'.': [
{
title: '分类',
docs: 'https://docs.rsshub.app/government.html#zhong-yang-wang-xin-ban',
source: ['/*'],
target: (params, url) => `/gov/cac/${new URL(url).href.match(/cac\.gov\.cn(.*?)\/(A.*?\.htm)/)[1]}`,
},
],
},
'ccdi.gov.cn': {
_name: '中央纪委国家监委',
www: [
Expand Down
1 change: 1 addition & 0 deletions lib/v2/gov/router.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = function (router) {
// ministry
router.get(/cac(\/[\w/-]+)?/, require('./cac/index'));
router.get(/ccdi(\/[\w/-]+)?/, require('./ccdi'));
router.get('/cmse/fxrw', require('./cmse/fxrw'));
router.get(/cmse(\/[\w/-]+)?/, require('./cmse'));
Expand Down
1 change: 1 addition & 0 deletions lib/v2/mihoyo/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
'/bbs/official/:gids/:type?/:page_size?/:last_id?': ['CaoMeiYouRen'],
'/sr/:location?/:category?': ['shinanory'],
'/ys/:location?/:category?': ['nczitzk'],
};
16 changes: 16 additions & 0 deletions lib/v2/mihoyo/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ module.exports = {
target: '/mihoyo/ys/:location',
},
],
hsr: [
{
title: '崩坏:星穹铁道 - 新闻',
docs: 'https://docs.rsshub.app/game.html##mi-ha-you',
source: '/:location/news',
target: '/mihoyo/sr/:location',
},
],
},
'mihoyo.com': {
_name: '米哈游',
Expand Down Expand Up @@ -38,6 +46,14 @@ module.exports = {
},
},
],
sr: [
{
title: '崩坏:星穹铁道 - 新闻',
docs: 'https://docs.rsshub.app/game.html##mi-ha-you',
source: '/news',
target: '/mihoyo/sr',
},
],
ys: [
{
title: '原神 - 新闻',
Expand Down
1 change: 1 addition & 0 deletions lib/v2/mihoyo/router.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = function (router) {
router.get('/bbs/official/:gids/:type?/:page_size?/:last_id?', require('./bbs'));
router.get('/sr/:location?/:category?', require('./sr/news'));
router.get('/ys/:location?/:category?', require('./ys/news'));
};
71 changes: 71 additions & 0 deletions lib/v2/mihoyo/sr/news.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');

const categories = {
'zh-cn': {
'news-all': {
id: '255',
title: '最新',
},
news: {
id: '256',
title: '新闻',
},
notice: {
id: '257',
title: '公告',
},
activity: {
id: '258',
title: '活动',
},
link: 'https://sr.mihoyo.com/news',
},
'zh-tw': {
'news-all': {
id: '248',
title: '最新',
},
news: {
id: '249',
title: '資訊',
},
notice: {
id: '250',
title: '公告',
},
activity: {
id: '251',
title: '活動',
},
link: 'https://hsr.hoyoverse.com/zh-tw/news',
},
};

module.exports = async (ctx) => {
// location 地区 category 类型
const { location = 'zh-cn', category = 'news-all' } = ctx.params;
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 50;
let url = '';
if (location === 'zh-cn') {
url = `https://api-takumi-static.mihoyo.com/content_v2_user/app/1963de8dc19e461c/getContentList?iPage=1&iPageSize=${limit}&sLangKey=zh-cn&isPreview=0&iChanId=${categories[location][category].id}`;
} else {
url = `https://api-os-takumi-static.hoyoverse.com/content_v2_user/app/113fe6d3b4514cdd/getContentList?iPage=1&iPageSize=${limit}&sLangKey=${location}&isPreview=0&iChanId=${categories[location][category].id}`;
}

const response = await got(url);
const list = response.data.data.list;
const items = list.map((item) => ({
title: item.sTitle,
description: item.sContent,
link: `${categories[location].link}/${item.iInfoId}`,
pubDate: parseDate(item.dtStartTime),
category: item.sCategoryName,
}));

ctx.state.data = {
title: `${categories[location][category].title}-崩坏:星穹铁道`,
link: url,
item: items,
};
};

1 comment on commit a742641

@vercel
Copy link

@vercel vercel bot commented on a742641 May 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.