feat(route): add 北京市科学技术协会 (#12299)
* chore(deps): bump chrono-node from 2.6.2 to 2.6.3 (#513) Bumps [chrono-node](https://github.com/wanasit/chrono) from 2.6.2 to 2.6.3. - [Release notes](https://github.com/wanasit/chrono/releases) - [Commits](https://github.com/wanasit/chrono/compare/v2.6.2...v2.6.3) --- updated-dependencies: - dependency-name: chrono-node dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump meilisearch from 0.32.2 to 0.32.3 (#518) Bumps [meilisearch](https://github.com/meilisearch/meilisearch-js) from 0.32.2 to 0.32.3. - [Release notes](https://github.com/meilisearch/meilisearch-js/releases) - [Commits](https://github.com/meilisearch/meilisearch-js/compare/v0.32.2...v0.32.3) --- updated-dependencies: - dependency-name: meilisearch dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): bump koa from 2.14.1 to 2.14.2 (#522) Bumps [koa](https://github.com/koajs/koa) from 2.14.1 to 2.14.2. - [Release notes](https://github.com/koajs/koa/releases) - [Changelog](https://github.com/koajs/koa/blob/2.14.2/History.md) - [Commits](https://github.com/koajs/koa/compare/2.14.1...2.14.2) --- updated-dependencies: - dependency-name: koa dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feat(route): add 北京市科学技术协会 * fix: revert yarn.lock * style: fix linebreak --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
dependabot[bot]
parent
64a5a7db1a
commit
08beb55f73
@@ -1731,6 +1731,26 @@ Supported sub-sites:
|
||||
|
||||
<Route author="emdoe" example="/twreporter/category/reviews" path="/twreporter/category/:tid" :paramsDesc="['分类(议题)名称,于主页获取']"/>
|
||||
|
||||
## 北京市科学技术协会
|
||||
|
||||
### 通用
|
||||
|
||||
<Route author="nczitzk" example="/bast/col/col31266" path="/bast/:path+" :paramsDesc="['路径,默认为通知公告']">
|
||||
|
||||
::: tip 提示
|
||||
|
||||
路径处填写对应页面 URL 中 `https://www.bast.net.cn/` 后的字段。下面是两个例子。
|
||||
|
||||
若订阅 [通知公告](https://www.bast.net.cn/col/col31266) 则将对应页面 URL <https://www.bast.net.cn/col/col31266> 中 `https://www.bast.net.cn/` 后的字段 `col/col31266` 作为路径填入。此时路由为 [`/bast/col/col31266`](https://rsshub.app/bast/col/col31266)
|
||||
|
||||
若订阅 [学术动态](https://www.bast.net.cn/col/col31530) 则将对应页面 URL <https://www.bast.net.cn/col/col31530> 中 `https://www.bast.net.cn/` 后的字段 `col/col31530` 作为路径填入。此时路由为 [`/bast/col/col31530`](https://rsshub.app/bast/col/col31530)
|
||||
|
||||
如果路由符合 `/col/colXXXXX` 的格式,可以由 [`/bast/col/col31266`](https://rsshub.app/bast/col/col31266) 精简为 [`/bast/31266`](https://rsshub.app/bast/31266)
|
||||
|
||||
:::
|
||||
|
||||
</Route>
|
||||
|
||||
## 北屋
|
||||
|
||||
<Route author="nczitzk" example="/northhouse" path="/northhouse/:category?" :paramsDesc="['分类,见下表,默认为首页']">
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const colPath = ctx.path.replace(/^\//, '') || '32942';
|
||||
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 50;
|
||||
|
||||
const rootUrl = 'https://www.bast.net.cn';
|
||||
const currentUrl = `${rootUrl}/${isNaN(colPath) ? colPath : `col/col${colPath}`}/`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
let $ = cheerio.load(response.data);
|
||||
|
||||
$('.list-title-bif').remove();
|
||||
|
||||
const title = $('title').text();
|
||||
let selection = $('a[title]');
|
||||
|
||||
if (selection.length === 0) {
|
||||
$ = cheerio.load($('ul.cont-list div script').first().text());
|
||||
|
||||
$('.list-title-bif').remove();
|
||||
|
||||
selection = $('a[title]');
|
||||
}
|
||||
|
||||
let items = selection
|
||||
.slice(0, limit)
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
|
||||
return {
|
||||
title: item.text().trim(),
|
||||
link: item.attr('href'),
|
||||
};
|
||||
});
|
||||
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
if (/bast\.net\.cn/.test(item.link)) {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.title = content('meta[name="ArticleTitle"]').attr('content');
|
||||
item.author = content('meta[name="contentSource"]').attr('content');
|
||||
item.pubDate = timezone(parseDate(content('meta[name="pubdate"]').attr('content')), +8);
|
||||
item.category = [content('meta[name="ColumnName"]').attr('content')];
|
||||
|
||||
item.description = content('.arccont').html();
|
||||
}
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title,
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/:path+': ['nczitzk'],
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
'bast.net.cn': {
|
||||
_name: '北京市科学技术协会',
|
||||
'.': [
|
||||
{
|
||||
title: '通用',
|
||||
docs: 'https://docs.rsshub.app/new-media.html#bei-jing-shi-ke-xue-ji-shu-xie-hui-tong-yong',
|
||||
source: ['/col', '/'],
|
||||
target: (params, url) => `/bast/${new URL(url).href.match(/bast\.net\.cn\/(.*)/)[1].replace(/\/index\.html/, '')}`,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = function (router) {
|
||||
router.get(/([\w-/]+)?/, require('./index'));
|
||||
};
|
||||
Reference in New Issue
Block a user