Skip to content

Commit

Permalink
Merge pull request #1320 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 Jan 12, 2024
2 parents 3d22aef + 836aa5b commit a1766f4
Show file tree
Hide file tree
Showing 37 changed files with 627 additions and 60 deletions.
3 changes: 2 additions & 1 deletion lib/v2/cyzone/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ const processItems = async (apiUrl, limit, tryGet, ...searchParams) => {
});

item.title = data.title;
item.link = /^\/\//.test(data.link_url) ? `https:${data.link_url}` : data.link_url;
// api 返回的 link_url 数据可能是空, 所有最好自己通过 id 拼接 url
item.link = `${rootUrl}/article/${item.guid}.html`;
item.description = content.html();
item.author = data.author_name ?? data.author;
item.category = [...new Set(categories)].filter((c) => c);
Expand Down
64 changes: 64 additions & 0 deletions lib/v2/ekantipur/issue.js
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,
};
};
3 changes: 3 additions & 0 deletions lib/v2/ekantipur/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/:channel?': ['maniche04'],
};
13 changes: 13 additions & 0 deletions lib/v2/ekantipur/radar.js
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',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/ekantipur/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:channel?', require('./issue'));
};
2 changes: 1 addition & 1 deletion lib/v2/gov/maintainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ module.exports = {
'/pbc/tradeAnnouncement': ['nczitzk'],
'/pbc/zcyj': ['Fatpandac'],
'/samr/xgzlyhd/:category?/:department?': ['nczitzk'],
'/safe/bussiness/:site?': ['nczitzk'],
'/safe/business/:site?': ['nczitzk'],
'/safe/complaint/:site?': ['nczitzk'],
'/sasac/:path+': ['TonyRL'],
'/stats/:path+': ['bigfei', 'nczitzk'],
Expand Down
4 changes: 2 additions & 2 deletions lib/v2/gov/safe/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ const processZxfkItems = async (site = 'beijing', category = 'ywzx', limit = '3'

return {
title: `${message.author}: ${message.content}`,
link: new URL(item.find('.title').prop('href'), rootUrl).href,
link: currentUrl,
description: art(path.join(__dirname, 'templates/message.art'), {
message,
reply,
}),
author: `${message.author}/${reply.author}`,
guid: item.find('.id').text(),
guid: `${currentUrl}#${message.author}(${message.date})/${reply.author}(${reply.date})`,
pubDate: parseDate(message.date),
updated: parseDate(reply.date),
};
Expand Down
47 changes: 47 additions & 0 deletions lib/v2/hoyolab/constant.js
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,
};
3 changes: 3 additions & 0 deletions lib/v2/hoyolab/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/news/:language/:gids/:type': ['ZenoTian'],
};
89 changes: 89 additions & 0 deletions lib/v2/hoyolab/news.js
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);
}
};
22 changes: 22 additions & 0 deletions lib/v2/hoyolab/radar.js
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}`;
},
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/hoyolab/router.js
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'));
};
34 changes: 34 additions & 0 deletions lib/v2/huggingface/blog-zh.js
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,
};
};
1 change: 1 addition & 0 deletions lib/v2/huggingface/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
'/blog-zh': ['zcf0508'],
'/daily-papers': ['zeyugao'],
};
6 changes: 6 additions & 0 deletions lib/v2/huggingface/radar.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ module.exports = {
source: ['/papers', '/'],
target: '/huggingface/daily-papers',
},
{
title: '中文博客',
docs: 'https://docs.rsshub.app/routes/programming#huggingface',
source: ['/blog/zh', '/'],
target: '/huggingface/blog-zh',
},
],
},
};
1 change: 1 addition & 0 deletions lib/v2/huggingface/router.js
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'));
};
3 changes: 3 additions & 0 deletions lib/v2/onet/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/news': ['Vegann'],
};
Loading

0 comments on commit a1766f4

Please sign in to comment.