* 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>
24 lines
822 B
JavaScript
24 lines
822 B
JavaScript
const got = require('@/utils/got');
|
|
const Cheerio = require('cheerio');
|
|
const { SUB_NAME_PREFIX, SUB_URL } = require('./const');
|
|
const loadArticle = require('./article');
|
|
const url = SUB_URL;
|
|
|
|
module.exports = async (ctx) => {
|
|
const limit = parseInt(ctx.query.limit);
|
|
const response = await got(url);
|
|
const itemRaw = Cheerio.load(response.body)('ul.post-loop li.item').toArray();
|
|
ctx.state.data = {
|
|
title: `${SUB_NAME_PREFIX}-最新`,
|
|
link: url,
|
|
item:
|
|
response.body &&
|
|
(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));
|
|
})
|
|
)),
|
|
};
|
|
};
|