* fix(route):route 8kcosplay: 子路由/category 无法获取 * feat(route):route 8kcosplay: 增加/tag * 一些修正 * doc:子路由/tag * style: * disable pre-commit hook * fix(route):route 8kcosplay: 最新文章无法获取 * fix(route):route 8kcosplay: 遵循pubDate规范 * style(route):route 8kcosplay: 遵循pubDate规范 * route 8kcosplay: 获取不到页面时不返回item * Revert "disable pre-commit hook" This reverts commit d1342b9ea2e422ea03d2fdd096dfa0a383529b7c. * fix(route):route 8kcosplay: 删除不必要的async * fix(route):route 8kcosplay: 限制文章全文获取数量 * use @/utils/got * feat(route):route 8kcosplay: 使用limit query限制文章全文获取数量 * refactor: migrated to v2 Co-authored-by: TonyRL <TonyRL@users.noreply.github.com>
23 lines
866 B
JavaScript
23 lines
866 B
JavaScript
const got = require('@/utils/got');
|
|
const Cheerio = require('cheerio');
|
|
const { SUB_NAME_PREFIX, SUB_URL } = require('./const');
|
|
const loadArticle = require('./article');
|
|
module.exports = async (ctx) => {
|
|
const limit = parseInt(ctx.query.limit);
|
|
const { cat = '8kasianidol' } = ctx.params;
|
|
const url = `${SUB_URL}category/${cat}/`;
|
|
const resp = await got(url);
|
|
const $ = Cheerio.load(resp.body);
|
|
const itemRaw = $('li.item').toArray();
|
|
ctx.state.data = {
|
|
title: `${SUB_NAME_PREFIX}-${$('span[property=name]:not(.hide)').text()}`,
|
|
link: url,
|
|
item: await Promise.all(
|
|
(limit ? itemRaw.slice(0, limit) : itemRaw).map((e) => {
|
|
const { href } = Cheerio.load(e)('h2 > a')[0].attribs;
|
|
return ctx.cache.tryGet(href, () => loadArticle(href));
|
|
})
|
|
),
|
|
};
|
|
};
|