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 #1320 from DIYgod/master
[pull] master from diygod:master
- Loading branch information
Showing
37 changed files
with
627 additions
and
60 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,64 @@ | ||
// Require necessary modules | ||
const got = require('@/utils/got'); // a customised got | ||
const cheerio = require('cheerio'); // an HTML parser with a jQuery-like API | ||
|
||
module.exports = async (ctx) => { | ||
// Your logic here | ||
// Defining base URL | ||
const baseUrl = 'https://ekantipur.com'; | ||
|
||
// Retrive the channel parameter | ||
const { channel = 'news' } = ctx.params; | ||
|
||
// Fetches content of the requested channel | ||
const { data: response } = await got(`${baseUrl}/${channel}`); | ||
const $ = cheerio.load(response); | ||
|
||
// Retrive articles | ||
const list = $('article.normal') | ||
// We use the `toArray()` method to retrieve all the DOM elements selected as an array. | ||
.toArray() | ||
// We use the `map()` method to traverse the array and parse the data we need from each element. | ||
.map((item) => { | ||
item = $(item); | ||
const a = item.find('a').first(); | ||
return { | ||
title: a.text(), | ||
// We need an absolute URL for `link`, but `a.attr('href')` returns a relative URL. | ||
link: `${baseUrl}${a.attr('href')}`, | ||
author: item.find('div.author').text(), | ||
category: channel, | ||
}; | ||
}); | ||
|
||
const items = await Promise.all( | ||
list.map((item) => | ||
ctx.cache.tryGet(item.link, async () => { | ||
const { data: response } = await got(item.link); | ||
const $ = cheerio.load(response); | ||
|
||
// Remove sponsor elements | ||
$('a.static-sponsor').remove(); | ||
$('div.ekans-wrapper').remove(); | ||
|
||
// Fetch title from the article page | ||
item.title = $('h1.eng-text-heading').text(); | ||
// Fetch article content from the article page | ||
item.description = $('div.current-news-block').first().html(); | ||
|
||
// Every property of a list item defined above is reused here | ||
// and we add a new property 'description' | ||
return item; | ||
}) | ||
) | ||
); | ||
|
||
ctx.state.data = { | ||
// channel title | ||
title: `Ekantipur - ${channel}`, | ||
// channel link | ||
link: `${baseUrl}/${channel}`, | ||
// each feed item | ||
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,3 @@ | ||
module.exports = { | ||
'/:channel?': ['maniche04'], | ||
}; |
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,13 @@ | ||
module.exports = { | ||
'ekantipur.com': { | ||
_name: 'Ekantipur', | ||
'.': [ | ||
{ | ||
title: 'Full Article RSS', | ||
docs: 'https://docs.rsshub.app/routes/traditional-media#ekantipur-%E0%A4%95%E0%A4%BE%E0%A4%A8%E0%A5%8D%E0%A4%A4%E0%A4%BF%E0%A4%AA%E0%A5%81%E0%A4%B0-nepal', | ||
source: ['/:channel'], | ||
target: '/ekantipur/:channel', | ||
}, | ||
], | ||
}, | ||
}; |
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,3 @@ | ||
module.exports = (router) => { | ||
router.get('/:channel?', require('./issue')); | ||
}; |
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,47 @@ | ||
// 域名 | ||
const HOST = 'https://bbs-api-os.hoyolab.com'; | ||
// 活动列接口 | ||
const EVENT_LIST = '/community/community_contribution/wapi/event/list'; | ||
// 活动详情接口 | ||
const POST_FULL = '/community/post/wapi/getPostFull'; | ||
// 公告和资讯接口 | ||
const NEW_LIST = '/community/post/wapi/getNewsList'; | ||
|
||
const ICON = 'https://img-os-static.hoyolab.com/favicon.ico'; | ||
// 源网站链接 | ||
const LINK = 'https://www.hoyolab.com'; | ||
|
||
// 部分图片使用了禁止公开访问的域名 | ||
const PRIVATE_IMG = '<img src="https://hoyolab-upload-private.hoyolab.com/upload'; | ||
// 使用以下域名可以替换 | ||
const PUBLIC_IMG = '<img src="https://upload-os-bbs.hoyolab.com/upload'; | ||
|
||
// 游戏id | ||
const GIDS_MAP = { | ||
1: 'Honkai Impact 3rd', | ||
2: '原神', | ||
4: '未定事件簿', | ||
5: 'HoYoLAB', | ||
6: '崩坏:星穹铁道', | ||
8: '绝区零', | ||
}; | ||
|
||
// 公告类型 | ||
const TYPE_MAP = { | ||
1: '公告', | ||
2: '活动', | ||
3: '资讯', | ||
}; | ||
|
||
module.exports = { | ||
PRIVATE_IMG, | ||
PUBLIC_IMG, | ||
LINK, | ||
ICON, | ||
POST_FULL, | ||
HOST, | ||
EVENT_LIST, | ||
NEW_LIST, | ||
GIDS_MAP, | ||
TYPE_MAP, | ||
}; |
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,3 @@ | ||
module.exports = { | ||
'/news/:language/:gids/:type': ['ZenoTian'], | ||
}; |
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,89 @@ | ||
const got = require('@/utils/got'); | ||
const logger = require('@/utils/logger'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
const { HOST, NEW_LIST, TYPE_MAP, POST_FULL, GIDS_MAP, LINK, ICON, PUBLIC_IMG, PRIVATE_IMG } = require('./constant'); | ||
|
||
const getEventList = async ({ type, gids, size, language }) => { | ||
const query = new URLSearchParams({ | ||
type, | ||
gids, | ||
page_size: size, | ||
}).toString(); | ||
const url = `${HOST}${NEW_LIST}?${query}`; | ||
const res = await got({ | ||
method: 'get', | ||
url, | ||
headers: { | ||
'X-Rpc-Language': language, | ||
}, | ||
}).json(); | ||
const list = res?.data?.list || []; | ||
return list; | ||
}; | ||
|
||
const replaceImgDomain = (content) => content.replaceAll(PRIVATE_IMG, PUBLIC_IMG); | ||
|
||
const getPostContent = (ctx, list, { type, language }) => | ||
Promise.all( | ||
list.map(async (row) => { | ||
const post = row.post; | ||
const post_id = post.post_id; | ||
const query = new URLSearchParams({ | ||
post_id, | ||
language, // language为了区分缓存,对接口并无意义 | ||
}).toString(); | ||
const url = `${HOST}${POST_FULL}?${query}`; | ||
return await ctx.cache.tryGet(url, async () => { | ||
const res = await got({ | ||
method: 'get', | ||
url, | ||
headers: { | ||
'X-Rpc-Language': language, | ||
}, | ||
}).json(); | ||
const author = res?.data?.post?.user?.nickname || ''; | ||
let content = res?.data?.post?.post?.content || ''; | ||
if (content === language || !content) { | ||
content = post.content; | ||
} | ||
const description = replaceImgDomain(content); | ||
return { | ||
// 文章标题 | ||
title: post.subject, | ||
// 文章链接 | ||
link: `${LINK}/article/${post_id}`, | ||
// 文章正文 | ||
description, | ||
// 文章发布日期 | ||
pubDate: parseDate(post.created_at * 1000), | ||
// 如果有的话,文章分类 | ||
category: `${GIDS_MAP[post.game_id]}-${TYPE_MAP[type]}`, | ||
author, | ||
}; | ||
}); | ||
}) | ||
); | ||
|
||
module.exports = async (ctx) => { | ||
try { | ||
const { type, gids, language } = ctx.params; | ||
const params = { | ||
type, | ||
gids, | ||
language, | ||
size: parseInt(ctx.query?.limit) || 15, | ||
}; | ||
const list = await getEventList(params); | ||
const items = await getPostContent(ctx, list, params); | ||
ctx.state.data = { | ||
title: `HoYoLAB-${GIDS_MAP[gids]}-${TYPE_MAP[type]}`, | ||
link: LINK, | ||
item: items, | ||
image: ICON, | ||
icon: ICON, | ||
logo: ICON, | ||
}; | ||
} catch (error) { | ||
logger.error(error); | ||
} | ||
}; |
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,22 @@ | ||
module.exports = { | ||
'hoyolab.com': { | ||
_name: 'HoYoLAB', | ||
'.': [ | ||
{ | ||
title: '活动公告资讯', | ||
docs: 'https://docs.rsshub.app/routes/game#hoyolab-news', | ||
source: ['/', '/circles/:gid/:unknow/official'], | ||
target: (params, url) => { | ||
const typeMap = { | ||
notices: '1', | ||
events: '2', | ||
news: '3', | ||
}; | ||
const query = new URL(url).searchParams; | ||
const type = typeMap[query.get('page_sort')] || '2'; | ||
return `/hoyolab/news/zh-cn/${params?.gid || 2}/${type}`; | ||
}, | ||
}, | ||
], | ||
}, | ||
}; |
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,3 @@ | ||
module.exports = (router) => { | ||
router.get('/news/:language/:gids/:type', require('./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,34 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
|
||
module.exports = async (ctx) => { | ||
const { body: response } = await got('https://huggingface.co/blog/zh'); | ||
const $ = cheerio.load(response); | ||
|
||
/** @type {Array<{blog: {local: string, title: string, author: string, thumbnail: string, date: string, tags: Array<string>}, blogUrl: string, lang: 'zh', link: string}>} */ | ||
const papers = $('div[data-target="BlogThumbnail"]') | ||
.toArray() | ||
.map((item) => { | ||
const props = $(item).data('props'); | ||
const link = $(item).find('a').attr('href'); | ||
return { | ||
...props, | ||
link, | ||
}; | ||
}); | ||
|
||
const items = papers.map((item) => ({ | ||
title: item.blog.title, | ||
link: `https://huggingface.co${item.link}`, | ||
category: item.blog.tags, | ||
pubDate: parseDate(item.blog.date), | ||
author: item.blog.author, | ||
})); | ||
|
||
ctx.state.data = { | ||
title: 'Huggingface 中文博客', | ||
link: 'https://huggingface.co/blog/zh', | ||
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
module.exports = { | ||
'/blog-zh': ['zcf0508'], | ||
'/daily-papers': ['zeyugao'], | ||
}; |
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,3 +1,4 @@ | ||
module.exports = (router) => { | ||
router.get('/blog-zh', require('./blog-zh')); | ||
router.get('/daily-papers', require('./daily-papers')); | ||
}; |
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,3 @@ | ||
module.exports = { | ||
'/news': ['Vegann'], | ||
}; |
Oops, something went wrong.