fix(route): MM范 (#8701)

* fix(route): MM范

* fix: add radar

* fix: use art-template
This commit is contained in:
Ethan Shen 2022-02-26 23:56:20 +08:00 committed by GitHub
parent dd430d1ab9
commit ef2e78f546
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 123 additions and 73 deletions

View File

@ -3331,9 +3331,9 @@ router.get('/huawei/xinsheng/:caty?/:order?/:keyword?', lazyloadRouteHandler('./
router.get('/ow/patch', lazyloadRouteHandler('./routes/ow/patch'));
// MM范
router.get('/95mm/tab/:tab?', lazyloadRouteHandler('./routes/95mm/tab'));
router.get('/95mm/tag/:tag', lazyloadRouteHandler('./routes/95mm/tag'));
router.get('/95mm/category/:category', lazyloadRouteHandler('./routes/95mm/category'));
// router.get('/95mm/tab/:tab?', lazyloadRouteHandler('./routes/95mm/tab'));
// router.get('/95mm/tag/:tag', lazyloadRouteHandler('./routes/95mm/tag'));
// router.get('/95mm/category/:category', lazyloadRouteHandler('./routes/95mm/category'));
// 中国工程科技知识中心
router.get('/cktest/app/:ctgroup?/:domain?', lazyloadRouteHandler('./routes/cktest/app'));

View File

@ -1,9 +0,0 @@
const utils = require('./utils');
module.exports = async (ctx) => {
ctx.params.tab = ctx.params.tab || '最新';
const rootUrl = `https://www.95mm.net/home-ajax/index.html?tabcid=${ctx.params.tab}&page=1`;
ctx.state.data = await utils(ctx, ctx.params.tab, rootUrl);
};

View File

@ -1,7 +0,0 @@
const utils = require('./utils');
module.exports = async (ctx) => {
const rootUrl = `https://www.95mm.net/tag-${ctx.params.tag}/page-1/index.html`;
ctx.state.data = await utils(ctx, ctx.params.tag, rootUrl);
};

View File

@ -1,51 +0,0 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx, title, rootUrl) => {
const response = await got({
method: 'get',
url: rootUrl,
header: {
Referer: 'https://www.95mm.net',
},
});
const $ = cheerio.load(response.data);
const list = $('div.list-body')
.map((_, item) => {
item = $(item);
const a = item.find('a');
return {
title: a.text(),
link: a.attr('href'),
};
})
.get();
const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const images = detailResponse.data.match(/src": '(.*?)',"width/g);
item.description = '';
for (const i of images) {
item.description += `<img src="${i.split("'")[1]}">`;
}
return item;
})
)
);
return {
title: `${title} - MM范`,
link: rootUrl,
item: items,
};
};

View File

@ -1,4 +1,4 @@
const utils = require('./utils');
const { rootUrl, ProcessItems } = require('./utils');
module.exports = async (ctx) => {
const categories = {
@ -12,7 +12,9 @@ module.exports = async (ctx) => {
11: '美女壁纸',
};
const rootUrl = `https://www.95mm.net/category-${ctx.params.category}/list-1/index.html?page=1`;
const category = ctx.params.category;
ctx.state.data = await utils(ctx, categories[ctx.params.category], rootUrl);
const currentUrl = `${rootUrl}/category-${category}/list-1/index.html?page=1`;
ctx.state.data = await ProcessItems(ctx, categories[category], currentUrl);
};

View File

@ -0,0 +1,5 @@
module.exports = {
'/tab/:tab?': ['nczitzk'],
'/tag/:tag': ['nczitzk'],
'/category/:category': ['nczitzk'],
};

25
lib/v2/95mm/radar.js Normal file
View File

@ -0,0 +1,25 @@
module.exports = {
'95mm.org': {
_name: 'MM范',
'.': [
{
title: '分类',
docs: 'https://docs.rsshub.app/picture.html#mm-fan-fen-lei',
source: '/',
target: '/95mm/tab/:tab?',
},
{
title: '标签',
docs: 'https://docs.rsshub.app/picture.html#mm-fan-biao-qian',
source: '/',
target: '/95mm/tag/:tag',
},
{
title: '集合',
docs: 'https://docs.rsshub.app/picture.html#mm-fan-ji-he',
source: '/',
target: '/95mm/category/:category',
},
],
},
};

5
lib/v2/95mm/router.js Normal file
View File

@ -0,0 +1,5 @@
module.exports = function (router) {
router.get('/tab/:tab?', require('./tab'));
router.get('/tag/:tag', require('./tag'));
router.get('/category/:category', require('./category'));
};

9
lib/v2/95mm/tab.js Normal file
View File

@ -0,0 +1,9 @@
const { rootUrl, ProcessItems } = require('./utils');
module.exports = async (ctx) => {
const tab = ctx.params.tab ?? '最新';
const currentUrl = `${rootUrl}/home-ajax/index.html?tabcid=${tab}&page=1`;
ctx.state.data = await ProcessItems(ctx, tab, currentUrl);
};

9
lib/v2/95mm/tag.js Normal file
View File

@ -0,0 +1,9 @@
const { rootUrl, ProcessItems } = require('./utils');
module.exports = async (ctx) => {
const tag = ctx.params.tag;
const currentUrl = `${rootUrl}/tag-${tag}/page-1/index.html`;
ctx.state.data = await ProcessItems(ctx, tag, currentUrl);
};

View File

@ -0,0 +1,3 @@
{{ each images }}
<img src="{{ $value }}">
{{ /each }}

59
lib/v2/95mm/utils.js Normal file
View File

@ -0,0 +1,59 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { art } = require('@/utils/render');
const path = require('path');
const rootUrl = 'https://www.95mm.org';
module.exports = {
rootUrl,
ProcessItems: async (ctx, title, currentUrl) => {
const response = await got({
method: 'get',
url: currentUrl,
header: {
Referer: rootUrl,
},
});
const $ = cheerio.load(response.data);
let items = $('div.list-body')
.toArray()
.map((item) => {
item = $(item);
const a = item.find('a');
return {
title: a.text(),
link: a.attr('href'),
};
});
items = await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const detailResponse = await got({
method: 'get',
url: item.link,
});
const images = detailResponse.data.match(/src": '(.*?)',"width/g);
item.description = art(path.join(__dirname, 'templates/description.art'), {
images: images.map((i) => i.split("'")[1]),
});
return item;
})
)
);
return {
title: `${title} - MM范`,
link: currentUrl,
item: items,
};
},
};