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.
Merge pull request #941 from DIYgod/master
[pull] master from diygod:master
- Loading branch information
Showing
10 changed files
with
195 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
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,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, | ||
}; | ||
}; |
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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
module.exports = { | ||
'/bbs/official/:gids/:type?/:page_size?/:last_id?': ['CaoMeiYouRen'], | ||
'/sr/:location?/:category?': ['shinanory'], | ||
'/ys/:location?/:category?': ['nczitzk'], | ||
}; |
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 |
---|---|---|
@@ -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')); | ||
}; |
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,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, | ||
}; | ||
}; |
a742641
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
rsshub-master – ./
rsshub-master.vercel.app
rsshub-master-git-master-auto-bot-ty.vercel.app
rsshub-master-auto-bot-ty.vercel.app