* chore(deps-dev): bump eslint-plugin-unicorn from 66.0.0 to 68.0.0 Bumps [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) from 66.0.0 to 68.0.0. - [Release notes](https://github.com/sindresorhus/eslint-plugin-unicorn/releases) - [Commits](https://github.com/sindresorhus/eslint-plugin-unicorn/compare/v66.0.0...v68.0.0) --- updated-dependencies: - dependency-name: eslint-plugin-unicorn dependency-version: 68.0.0 dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> * style: fix no-useless-coercion * style: fix prefer-boolean-return * style: fix no-useless-logical-operand * style: fix prefer-single-replace * style: fix consistent-conditional-object-spread * style: fix no-useless-else * style: fix prefer-unicode-code-point-escapes * style: fix operator-assignment * style: fix prefer-continue * style: fix prefer-math-constants * style: fix prefer-hoisting-branch-code * style: fix prefer-array-slice * style: fix consistent-class-member-order * style: fix no-return-array-push * style: fix prefer-promise-with-resolvers * style: fix no-array-concat-in-loop * style: fix no-loop-iterable-mutation * style: fix no-invalid-argument-count * style: fix no-duplicate-if-branches * style: fix prefer-else-if * style: fix no-unreadable-for-of-expression * style: fix logical-assignment-operators * style: fix default-export-style * style: revert false positve in prefer-type-literal-last in #22274 * style: fix arrow-body-style * style: add v68 recommended preset * style: refactor GraphQL queries to use template literals for better readability --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Tony <TonyRL@users.noreply.github.com>
103 lines
4.3 KiB
TypeScript
103 lines
4.3 KiB
TypeScript
import { load } from 'cheerio';
|
|
|
|
import type { Route } from '@/types';
|
|
import { ViewType } from '@/types';
|
|
import cache from '@/utils/cache';
|
|
import ofetch from '@/utils/ofetch';
|
|
import { parseDate } from '@/utils/parse-date';
|
|
import timezone from '@/utils/timezone';
|
|
|
|
export const route: Route = {
|
|
path: '/cs/:category?',
|
|
name: '计算机学院',
|
|
url: 'cs.hrbust.edu.cn',
|
|
maintainers: ['cscnk52'],
|
|
handler,
|
|
example: '/hrbust/cs',
|
|
parameters: { category: '栏目标识,默认为 3709(学院要闻)' },
|
|
description: `| 通知公告 | 学院要闻 | 常用下载 | 博士后流动站 | 学生指导 | 科研动态 | 科技成果 | 党建理论 | 党建学习 | 党建活动 | 党建风采 | 团学组织 | 学生党建 | 学生活动 | 心理健康 | 青春榜样 | 就业工作 | 校友风采 | 校庆专栏 | 专业介绍 | 本科生培养方案 | 硕士生培养方案 | 能力作风建设 | 博士生培养方案 | 省级实验教学示范中心 | 喜迎二十大系列活动 | 学习贯彻省十三次党代会精神 |
|
|
| -------- | -------- | -------- | ------------ | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------- | -------------- | -------------- | ------------ | -------------- | -------------------- | ------------------ | -------------------------- |
|
|
| 3708 | 3709 | 3710 | 3725 | 3729 | 3732 | 3733 | 3740 | 3741 | 3742 | 3743 | 3744 | 3745 | 3746 | 3747 | 3748 | 3751 | 3752 | 3753 | 3755 | 3756 | 3759 | nlzfjs | pyfa | sjsyjxsfzx | srxxgcddesdjs | xxgcssscddhjs |`,
|
|
categories: ['university'],
|
|
features: {
|
|
requireConfig: false,
|
|
requirePuppeteer: false,
|
|
antiCrawler: false,
|
|
supportBT: false,
|
|
supportPodcast: false,
|
|
supportScihub: false,
|
|
supportRadar: true,
|
|
},
|
|
radar: [
|
|
{
|
|
source: ['cs.hrbust.edu.cn/:category/list.htm'],
|
|
target: '/cs/:category',
|
|
},
|
|
{
|
|
source: ['cs.hrbust.edu.cn'],
|
|
target: '/cs',
|
|
},
|
|
],
|
|
view: ViewType.Notifications,
|
|
};
|
|
|
|
async function handler(ctx) {
|
|
const rootUrl = 'https://cs.hrbust.edu.cn/';
|
|
const { category = 3709 } = ctx.req.param();
|
|
const columnUrl = `${rootUrl}${category}/list.htm`;
|
|
const response = await ofetch(columnUrl);
|
|
const $ = load(response);
|
|
const bigTitle = $('li.col_title').text();
|
|
|
|
const list = $('div.col_news_con li.news')
|
|
.toArray()
|
|
.map((item) => {
|
|
const element = $(item);
|
|
const link = new URL(element.find('a').attr('href'), rootUrl).href;
|
|
const pubDateText = element.find('span.news_meta').text().trim();
|
|
const pubDate = pubDateText ? timezone(parseDate(pubDateText), 8) : null;
|
|
return {
|
|
title: element.find('a').text().trim(),
|
|
pubDate,
|
|
link,
|
|
};
|
|
});
|
|
|
|
const items = await Promise.all(
|
|
list.map((item) =>
|
|
cache.tryGet(item.link, async () => {
|
|
if (!item.link.startsWith(rootUrl)) {
|
|
item.description = '本文需跳转,请点击原文链接后阅读';
|
|
return item;
|
|
}
|
|
|
|
const response = await ofetch(item.link);
|
|
const $ = load(response);
|
|
const content = $('div.wp_articlecontent');
|
|
|
|
content.find('[style]').removeAttr('style');
|
|
content.find('font').contents().unwrap();
|
|
content.html(content.html()?.replaceAll(' ', ''));
|
|
content.find('[align]').removeAttr('align');
|
|
|
|
const author = $('span.arti_publisher').text().replace('发布者:', '').trim();
|
|
|
|
return {
|
|
title: item.title,
|
|
link: item.link,
|
|
pubDate: item.pubDate,
|
|
description: content.html(),
|
|
author,
|
|
};
|
|
})
|
|
)
|
|
);
|
|
|
|
return {
|
|
title: `${bigTitle} - 哈尔滨理工大学计算机学院`,
|
|
link: columnUrl,
|
|
language: 'zh-CN',
|
|
item: items,
|
|
};
|
|
}
|