From 517d29da2cd03e5ddf5cae42d548a0016e91b3c1 Mon Sep 17 00:00:00 2001 From: Gandum2077 Date: Sun, 8 Nov 2020 09:31:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E7=B4=B3=E5=A3=AB=E6=BC=AB?= =?UTF-8?q?=E7=95=AB=20=E5=88=86=E7=B1=BB=E6=9B=B4=E6=96=B0=20(#6120)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/anime.md | 4 +++ lib/router.js | 1 + lib/routes/ssmh/category.js | 50 +++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 lib/routes/ssmh/category.js diff --git a/docs/anime.md b/docs/anime.md index cc18fb87f..bcc037374 100644 --- a/docs/anime.md +++ b/docs/anime.md @@ -332,6 +332,10 @@ pageClass: routes +### 分类更新 + + + ## 鼠绘漫画 ### 鼠绘漫画 diff --git a/lib/router.js b/lib/router.js index fd5c5ea0e..d36704c2e 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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')); diff --git a/lib/routes/ssmh/category.js b/lib/routes/ssmh/category.js new file mode 100644 index 000000000..a10983092 --- /dev/null +++ b/lib/routes/ssmh/category.js @@ -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: ``, + link: link_url, + }; + }) + .get(), + }; +};