* 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 中国管理现代化研究会 * style: fix linebreak --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
const got = require('@/utils/got');
|
|
const cheerio = require('cheerio');
|
|
|
|
module.exports = async (ctx) => {
|
|
const id = ctx.params.id ?? '1';
|
|
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 50;
|
|
|
|
const rootUrl = 'http://www.camchina.org.cn';
|
|
const currentUrl = `${rootUrl}/categories/${id}`;
|
|
|
|
const response = await got({
|
|
method: 'get',
|
|
url: currentUrl,
|
|
});
|
|
|
|
const $ = cheerio.load(response.data);
|
|
|
|
let items = $('.M-main-l p a')
|
|
.slice(0, limit)
|
|
.toArray()
|
|
.map((item) => {
|
|
item = $(item);
|
|
|
|
return {
|
|
title: item.text(),
|
|
link: `${rootUrl}${item.attr('href')}`,
|
|
};
|
|
});
|
|
|
|
items = await Promise.all(
|
|
items.map((item) =>
|
|
ctx.cache.tryGet(item.link, async () => {
|
|
const detailResponse = await got({
|
|
method: 'get',
|
|
url: item.link,
|
|
});
|
|
|
|
const content = cheerio.load(detailResponse.data);
|
|
|
|
item.description = content('.content').html();
|
|
|
|
return item;
|
|
})
|
|
)
|
|
);
|
|
|
|
ctx.state.data = {
|
|
title: `中国管理现代化研究会 - ${$('.title_red').text()}`,
|
|
link: currentUrl,
|
|
item: items,
|
|
};
|
|
};
|