Files
RSSHub/lib/routes/hrbust/lib.ts
T
dependabot[bot]andTony 417ab04f06 chore(deps-dev): bump eslint-plugin-unicorn from 66.0.0 to 68.0.0 (#22310)
* 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>
2026-06-20 23:11:27 +08:00

100 lines
3.6 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: '/lib/:category?',
name: '图书馆',
url: 'lib.hrbust.edu.cn',
maintainers: ['cscnk52'],
handler,
example: '/hrbust/lib',
parameters: { category: '栏目标识,默认为 3421(公告消息)' },
description: `| 公告消息 | 资源动态 | 参考中心 | 常用工具 | 外借服务 | 报告厅及研讨间服务 | 外文引进数据库 | 外文电子图书 | 外文试用数据库 | 中文引进数据库 | 中文电子图书 | 中文试用数据库 |
| -------- | -------- | -------- | -------- | -------- | ------------------ | -------------- | ------------ | -------------- | -------------- | ------------ | -------------- |
| 3421 | 3422 | ckzx | cygj | wjfw | ytjfw | yw | yw\\_3392 | yw\\_3395 | zw | zw\\_3391 | zw\\_3394 |`,
categories: ['university'],
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
supportRadar: true,
},
radar: [
{
source: ['lib.hrbust.edu.cn/:category/list.htm'],
target: '/lib/:category',
},
{
source: ['lib.hrbust.edu.cn'],
target: '/lib',
},
],
view: ViewType.Notifications,
};
async function handler(ctx) {
const rootUrl = 'https://lib.hrbust.edu.cn/';
const { category = 3421 } = ctx.req.param();
const columnUrl = `${rootUrl}${category}/list.htm`;
const response = await ofetch(columnUrl);
const $ = load(response);
const bigTitle = $('span.Column_Anchor').text();
const list = $('ul.tu_b3 li:not([class])')
.toArray()
.map((item) => {
const element = $(item);
const link = new URL(element.find('a').attr('href'), rootUrl).href;
const pubDateText = element.find('span').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('&nbsp;', ''));
content.find('[align]').removeAttr('align');
return {
title: item.title,
link: item.link,
pubDate: item.pubDate,
description: content.html(),
};
})
)
);
return {
title: `${bigTitle} - 哈尔滨理工大学图书馆`,
link: columnUrl,
language: 'zh-CN',
item: items,
};
}