fix(route): fix douban/explore route is empty (#8968)
* Fix(route): fix route is empty * Fix(route): resolve merge conflicts * Fix(route): change to use art-template
This commit is contained in:
parent
5d83517090
commit
d72dce4056
|
|
@ -809,7 +809,7 @@ YouTube 官方亦有提供频道 RSS,形如 <https://www.youtube.com/feeds/vid
|
|||
|
||||
### 浏览发现
|
||||
|
||||
<Route author="clarkzsd" example="/douban/explore" path="/douban/explore"/>
|
||||
<Route author="clarkzsd Fatpandac" example="/douban/explore" path="/douban/explore"/>
|
||||
|
||||
### 浏览发现分栏目
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const { art } = require('@/utils/render');
|
||||
const path = require('path');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const response = await got({
|
||||
|
|
@ -10,8 +12,7 @@ module.exports = async (ctx) => {
|
|||
const data = response.data;
|
||||
|
||||
const $ = cheerio.load(data);
|
||||
const list = $('div[data-item_id]');
|
||||
let itemPicUrl;
|
||||
const list = $('div.item');
|
||||
|
||||
ctx.state.data = {
|
||||
title: '豆瓣-浏览发现',
|
||||
|
|
@ -19,13 +20,29 @@ module.exports = async (ctx) => {
|
|||
item:
|
||||
list &&
|
||||
list
|
||||
.map((index, item) => {
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
itemPicUrl = item.find('a.cover').attr('style').replace('background-image:url(', '').replace(')', '');
|
||||
|
||||
const title = item.find('.title a').first().text() ? item.find('.title a').first().text() : '#' + item.find('.icon-topic').text();
|
||||
const desc = item.find('.content p').text();
|
||||
const itemPic = item.find('a.cover').attr('style')
|
||||
? item
|
||||
.find('a.cover')
|
||||
.attr('style')
|
||||
.match(/\('(.*?)'\)/)[1]
|
||||
: '';
|
||||
const author = item.find('.usr-pic a').last().text();
|
||||
const link = item.find('.title a').attr('href') ?? item.find('.icon-topic a').attr('href');
|
||||
|
||||
return {
|
||||
title: item.find('.title a').first().text(),
|
||||
description: `作者:${item.find('.usr-pic a').last().text()}<br>描述:${item.find('.content p').text()}<br><img src="${itemPicUrl}">`,
|
||||
link: item.find('.title a').attr('href'),
|
||||
title,
|
||||
author,
|
||||
description: art(path.join(__dirname, '../templates/explore.art'), {
|
||||
author,
|
||||
desc,
|
||||
itemPic,
|
||||
}),
|
||||
link,
|
||||
};
|
||||
})
|
||||
.get(),
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
作者:{{author}}
|
||||
<br>
|
||||
描述:{{desc}}
|
||||
<br>
|
||||
{{ if itemPic }}
|
||||
<img src={{ itemPic }}>
|
||||
{{ /if }}
|
||||
Loading…
Reference in New Issue