mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
fix(route): dongqiudi (#13781)
This commit is contained in:
+13
-21
@@ -1,32 +1,24 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const utils = require('./utils');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
const response = await got(`https://www.dongqiudi.com/special/${id}`);
|
||||
const { data: response } = await got(`https://www.dongqiudi.com/api/old/columns/${id}`);
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const host = 'https://www.dongqiudi.com';
|
||||
|
||||
const list = $('.detail.special ul li h3')
|
||||
.slice(0, ctx.query.limit ? Number(ctx.query.limit) : 5)
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.find('a').text(),
|
||||
link: host + item.find('a').attr('href'),
|
||||
};
|
||||
});
|
||||
const list = response.data.map((item) => ({
|
||||
title: item.title,
|
||||
link: `https://www.dongqiudi.com/articles/${item.aid}.html`,
|
||||
mobileLink: `https://m.dongqiudi.com/article/${item.aid}.html`,
|
||||
pubDate: parseDate(item.show_time, 'X'),
|
||||
}));
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const { data: response } = await got(item.link);
|
||||
const { data: response } = await got(item.mobileLink);
|
||||
|
||||
utils.ProcessFeedType2(item, response);
|
||||
utils.ProcessFeedType3(item, response);
|
||||
|
||||
return item;
|
||||
})
|
||||
@@ -34,9 +26,9 @@ module.exports = async (ctx) => {
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `懂球帝专题-${$('.detail.special h1').text()}`,
|
||||
description: $('.detail.special h4').text(),
|
||||
title: `懂球帝专题-${response.title}`,
|
||||
description: response.description,
|
||||
link: `https://www.dongqiudi.com/special/${id}`,
|
||||
item: out.filter((e) => e !== undefined),
|
||||
item: out.filter((e) => e),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -129,7 +129,7 @@ const ProcessFeedType2 = (item, response) => {
|
||||
}
|
||||
|
||||
if (Object.keys(data).length > 0) {
|
||||
const body = ProcessVideo(cheerio.load(data.body));
|
||||
const body = ProcessVideo(cheerio.load(data.body, null, false));
|
||||
ProcessHref(body('a'));
|
||||
ProcessImg(body('img'));
|
||||
item.description = body.html();
|
||||
@@ -138,10 +138,34 @@ const ProcessFeedType2 = (item, response) => {
|
||||
}
|
||||
};
|
||||
|
||||
const ProcessFeedType3 = (item, response) => {
|
||||
const $ = cheerio.load(response);
|
||||
const initialState = JSON.parse(
|
||||
$('script:contains("window.__INITIAL_STATE__")')
|
||||
.text()
|
||||
.match(/window\.__INITIAL_STATE__\s*=\s*(.*?);\(/)[1]
|
||||
);
|
||||
|
||||
// filter out undefined item
|
||||
if (!initialState) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Object.keys(initialState.articleContent).length) {
|
||||
const data = Object.values(initialState.articleContent)[0];
|
||||
const body = ProcessVideo(cheerio.load(data.body, null, false));
|
||||
ProcessHref(body('a'));
|
||||
ProcessImg(body('img'));
|
||||
item.description = body.html();
|
||||
item.author = data.writer;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
ProcessVideo,
|
||||
ProcessFeed,
|
||||
ProcessFeedType2,
|
||||
ProcessFeedType3,
|
||||
ProcessHref,
|
||||
ProcessImg,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user