fix: 修复 iFanr 无法订阅 大声 栏目的问题 (#2006)
This commit is contained in:
parent
33585e5a1e
commit
cee80646b7
|
|
@ -2,10 +2,11 @@ const axios = require('../../utils/axios');
|
|||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
let host = 'http://www.ifanr.com';
|
||||
let host = 'https://www.ifanr.com';
|
||||
|
||||
let channel;
|
||||
if (ctx.params.channel) {
|
||||
let channel = ctx.params.channel.toLowerCase();
|
||||
channel = ctx.params.channel.toLowerCase();
|
||||
channel = channel.split('-').join('/');
|
||||
|
||||
// 兼容旧版路由
|
||||
|
|
@ -16,15 +17,28 @@ module.exports = async (ctx) => {
|
|||
}
|
||||
} else {
|
||||
host = `${host}/app`;
|
||||
channel = 'app';
|
||||
}
|
||||
|
||||
const response = await axios.get(host);
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('h3 a')
|
||||
.map((i, e) => $(e).attr('href'))
|
||||
.get();
|
||||
let list;
|
||||
switch (channel) {
|
||||
case 'dasheng':
|
||||
list = $('#articles-collection')
|
||||
.find('.c-bricks__brick a.c-dasheng')
|
||||
.map((i, e) => $(e).attr('href'))
|
||||
.get();
|
||||
break;
|
||||
default:
|
||||
list = $('#articles-collection')
|
||||
.find('.article-item .article-info h3 a')
|
||||
.map((i, e) => $(e).attr('href'))
|
||||
.get();
|
||||
break;
|
||||
}
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (itemUrl) => {
|
||||
|
|
@ -35,22 +49,26 @@ module.exports = async (ctx) => {
|
|||
|
||||
const response = await axios.get(itemUrl);
|
||||
const $ = cheerio.load(response.data);
|
||||
const title = $('h1').text();
|
||||
|
||||
const single = {
|
||||
title,
|
||||
const item = {
|
||||
title: $('.c-single-normal__title').text(),
|
||||
link: itemUrl,
|
||||
author: $('.c-article-header-meta__category').html(),
|
||||
author: $('.c-card-author__name').text(),
|
||||
description: $('article').html(),
|
||||
pubDate: new Date($('.c-article-header-meta__time').attr('data-timestamp') * 1000),
|
||||
};
|
||||
ctx.cache.set(itemUrl, JSON.stringify(single), 24 * 60 * 60);
|
||||
return Promise.resolve(single);
|
||||
// "大声" 标题
|
||||
if (/^https?:\/\/www\.ifanr\.com\/dasheng\/.*$/.test(itemUrl)) {
|
||||
item.title = $('.c-dasheng_header__title').text();
|
||||
}
|
||||
|
||||
ctx.cache.set(itemUrl, JSON.stringify(item), 24 * 60 * 60);
|
||||
return Promise.resolve(item);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${$('h1.c-archive-header__title').text()}:${$('div.c-archive-header__desc').text()}`,
|
||||
title: `iFanr - ${$('h1.c-archive-header__title').text()}:${$('div.c-archive-header__desc').text()}`,
|
||||
link: host,
|
||||
item: out,
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue