feat:add 8kcosplay (#6097)

This commit is contained in:
KotoriK 2020-11-08 09:18:01 +08:00 committed by GitHub
parent cb18d41b50
commit ecd784fc4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 90 additions and 0 deletions

View File

@ -36,6 +36,16 @@ pageClass: routes
</Route>
## 8KCosplay
### 最新
<Route author="KotoriK" example="/8kcos/" path="/8kcos/"/>
### 分类
<Route author="KotoriK" example="/8kcos/cat/8kasianidol" path="/8kcos/cat/:cat*" :paramsDesc="['默认值为8kasianidol将目录页面url中 /category/ 后面的部分填入。如https://www.8kcosplay.com/category/8kchineseidol/%e9%a3%8e%e4%b9%8b%e9%a2%86%e5%9f%9f/ 对应的RSS页面为/8kcos/cat/8kchineseidol/%e9%a3%8e%e4%b9%8b%e9%a2%86%e5%9f%9f/。']"/>
## Bing 壁纸
### 每日壁纸

View File

@ -3468,4 +3468,8 @@ router.get('/grandchallenge/challenges', require('./routes/grandchallenge/challe
// 西北工业大学
router.get('/nwpu/:column', require('./routes/nwpu/index'));
// 8kcos
router.get('/8kcos/', require('./routes/8kcos/latest'));
router.get('/8kcos/cat/:cat*', require('./routes/8kcos/cat'));
module.exports = router;

View File

@ -0,0 +1,17 @@
const Cheerio = require('cheerio');
const got = require('got');
async function loadArticle(link) {
const resp = await got(link);
const article = Cheerio.load(resp.body);
const title = article('.entry-title').text();
const entry_children = article('div.entry-content').children().toArray();
const imgs = Cheerio.load(entry_children.shift()).text(); // 去除懒加载代码减少返回体积
const txt = Cheerio.load(entry_children).html();
return {
title,
description: imgs.concat(txt),
pubDate: article('time')[0].attribs.datetime.replace('>', ''),
link,
};
}
module.exports = loadArticle;

28
lib/routes/8kcos/cat.js Normal file
View File

@ -0,0 +1,28 @@
const got = require('got');
const Cheerio = require('cheerio');
const { SUB_NAME_PREFIX, SUB_URL } = require('./const');
const loadArticle = require('./article');
module.exports = async (ctx) => {
const { cat = '8kasianidol' } = ctx.params;
const url = `${SUB_URL}category/${cat}/`;
const resp = await got(url);
const $ = Cheerio.load(resp.body);
ctx.state.data = resp.body
? {
title: `${SUB_NAME_PREFIX}-${$('#wrap > div > div > div > div.sec-panel-head > h1 > span').text()}`,
link: url,
item: await Promise.all(
Cheerio.load(resp.body)('#wrap > div > div > div > ul > li.item')
.map((_, e) => {
const { href } = Cheerio.load(e)('h2 > a')[0].attribs;
return ctx.cache.tryGet(href, async () => loadArticle(href));
})
.toArray()
),
}
: {
title: `${SUB_NAME_PREFIX}-${cat}`,
link: url,
item: [{ title: '获取失败' }],
};
};

View File

@ -0,0 +1,4 @@
module.exports = {
SUB_NAME_PREFIX: '8KCosplay',
SUB_URL: 'https://www.8kcosplay.com/',
};

View File

@ -0,0 +1,27 @@
const got = require('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 response = await got(url);
ctx.state.data = {
title: `${SUB_NAME_PREFIX}-最新`,
link: url,
item: response.body
? await Promise.all(
Cheerio.load(response.body)('#wrap > div > div > div > ul > li.item')
.map((_, e) => {
const { href } = Cheerio.load(e)('div > h2 > a')[0].attribs;
return ctx.cache.tryGet(href, async () => loadArticle(href));
})
.toArray()
)
: [
{
title: '获取失败!',
},
],
};
};