mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-24 23:12:34 +08:00
fix: switch to Dcard post api (#4041)
This commit is contained in:
@@ -36,9 +36,7 @@ module.exports = async (ctx) => {
|
||||
},
|
||||
});
|
||||
|
||||
const data = response.data;
|
||||
|
||||
const items = await utils.ProcessFeed(data, ctx.cache);
|
||||
const items = await utils.ProcessFeed(response.data, ctx.cache);
|
||||
|
||||
ctx.state.data = {
|
||||
title,
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const ProcessFeed = async (list, cache) => {
|
||||
const result = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
const link = `https://www.dcard.tw/f/${item.forumAlias}/p/${item.id}`;
|
||||
const url = `https://www.dcard.tw/_api/posts/${item.id}`;
|
||||
|
||||
const content = await cache.tryGet(`dcard${item.id}`, async () => {
|
||||
let response;
|
||||
@@ -14,15 +13,21 @@ const ProcessFeed = async (list, cache) => {
|
||||
try {
|
||||
response = await got({
|
||||
method: 'get',
|
||||
url: link,
|
||||
url,
|
||||
headers: {
|
||||
Referer: 'https://www.dcard.tw/f',
|
||||
},
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
let body = response.data.content;
|
||||
|
||||
return $('.Post_content_NKEl9d > div:nth-child(1)').html();
|
||||
body = body.replace(/(?=https?:\/\/).*?(?<=\.(jpe?g|gif|png))/gi, (m) => `<img src="${m}">`);
|
||||
|
||||
body = body.replace(/(?=https?:\/\/).*(?<!jpe?g"?>?)$/gim, (m) => `<a href="${m}">${m}</a>`);
|
||||
|
||||
body = body.replace(/\n/g, '<br>');
|
||||
|
||||
return body;
|
||||
} catch (error) {
|
||||
return '';
|
||||
}
|
||||
@@ -30,7 +35,7 @@ const ProcessFeed = async (list, cache) => {
|
||||
|
||||
const single = {
|
||||
title: `「${item.forumName}」${item.title}`,
|
||||
link,
|
||||
link: `https://www.dcard.tw/f/${item.forumAlias}/p/${item.id}`,
|
||||
description: content,
|
||||
author: item.school || '匿名',
|
||||
pubDate: item.createdAt,
|
||||
|
||||
Reference in New Issue
Block a user