feat: add 紳士漫畫 分类更新 (#6120)

This commit is contained in:
Gandum2077 2020-11-08 09:31:25 +08:00 committed by GitHub
parent b6d4b08aac
commit 517d29da2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 0 deletions

View File

@ -332,6 +332,10 @@ pageClass: routes
<Route author="KenMizz" example="/ssmh" path="/ssmh/" />
### 分类更新
<Route author="Gandum2077" example="/ssmh/category/6" path="/ssmh/category/:cid" :paramsDesc="['分类的id即对应 URL 中的数字']" />
## 鼠绘漫画
### 鼠绘漫画

View File

@ -2717,6 +2717,7 @@ router.get('/eastmoney/user/:uid', require('./routes/eastmoney/user'));
// 紳士漫畫
router.get('/ssmh', require('./routes/ssmh'));
router.get('/ssmh/category/:cid', require('./routes/ssmh/category'));
// 武昌首义学院
router.get('/wsyu/news/:type?', require('./routes/universities/wsyu/news'));

View File

@ -0,0 +1,50 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const categories = {
1: '同人誌 漢化',
2: '同人誌 CG畫集',
3: '同人誌 Cosplay',
5: '同人誌',
6: '單行本',
7: '雜誌&短篇',
9: '單行本 漢化',
10: '雜誌&短篇 漢化',
12: '同人誌 日語',
13: '單行本 日語',
14: '雜誌&短篇 日語',
};
module.exports = async (ctx) => {
const cid = ctx.params.cid;
if (!cid || !Object.keys(categories).includes(cid)) {
ctx.state.data = {
title: '此分类不存在',
};
return;
}
const url = `https://www.wnacg.com/albums-index-cate-${cid}.html`;
const response = await got.get(url);
const data = response.data;
const $ = cheerio.load(data);
const list = $('.pic_box');
ctx.state.data = {
title: '紳士漫畫 - ' + categories[cid],
link: url,
item: list
.map((index, item) => {
item = $(item);
const thumbnail_url = 'https:' + `${item.find('a > img').attr('data-original')}`;
const link_url = 'https://wnacg.org' + `${item.find('a').attr('href')}`;
return {
title: item.find('a').attr('title'),
description: `<img src=${thumbnail_url} referrerpolicy="no-referrer">`,
link: link_url,
};
})
.get(),
};
};