feat: 低端影视 各作品列表页面路由 (#3908)

This commit is contained in:
hoilc
2020-02-07 03:31:30 +08:00
committed by GitHub
parent c8afd2088f
commit 201d6cbdfe
4 changed files with 85 additions and 3 deletions

37
lib/routes/ddrk/list.js Normal file
View File

@@ -0,0 +1,37 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const md5 = require('@/utils/md5');
module.exports = async (ctx) => {
const url = ctx.params.tag ? `https://ddrk.me/tag/${encodeURIComponent(ctx.params.tag)}/` : ctx.params.category ? `https://ddrk.me/category/${ctx.params.category}/` : 'https://ddrk.me/';
const response = await got(url);
const $ = cheerio.load(response.data);
const title = $('title').html();
const list = $('.post-box-list .post-box-container').toArray();
ctx.state.data = {
title: title,
link: url,
item: list.map((single, index) => {
const item = $(single);
const name = item.find('.post-box-title').text();
const poster = item
.find('.post-box-image')
.attr('style')
.match(/url\((.*?)\)/)[1];
const text = item.find('.post-box-text p').html();
const time = new Date();
time.setMinutes(time.getMinutes() - index);
return {
title: name,
author: '低端影视',
description: `<img src="${poster}" style="max-width: 100%;" >${text ? text : ''}`,
link: item.find('.post-box-title a').attr('href'),
pubDate: time,
guid: md5(name),
};
}),
};
};