diff --git a/assets/radar-rules.js b/assets/radar-rules.js
index 6bd1c0680..8587f6ace 100644
--- a/assets/radar-rules.js
+++ b/assets/radar-rules.js
@@ -131,15 +131,6 @@
],
},
'bing.com': { _name: 'Bing', www: [{ title: '每日壁纸', docs: 'https://docs.rsshub.app/picture.html#bing-bi-zhi', source: '', target: '/bing' }] },
- 'dcard.tw': {
- _name: 'Dcard',
- www: [
- { title: '首頁帖子-最新', docs: 'https://docs.rsshub.app/bbs.html#dcard', source: '/f', target: '/dcard/posts/latest' },
- { title: '首頁帖子-熱門', docs: 'https://docs.rsshub.app/bbs.html#dcard', source: '/f', target: '/dcard/posts/popular' },
- { title: '板塊帖子-最新', docs: 'https://docs.rsshub.app/bbs.html#dcard', source: '/f/:section', target: '/dcard/:section/latest' },
- { title: '板塊帖子-熱門', docs: 'https://docs.rsshub.app/bbs.html#dcard', source: '/f/:section', target: '/dcard/:section/popular' },
- ],
- },
'wegene.com': {
_name: 'WeGene',
www: [
diff --git a/docs/bbs.md b/docs/bbs.md
index 5773e3119..9af90a943 100644
--- a/docs/bbs.md
+++ b/docs/bbs.md
@@ -132,11 +132,11 @@ pageClass: routes
### 首頁帖子
-
+
### 板塊帖子
-
+
## Discuz
diff --git a/lib/radar-rules.js b/lib/radar-rules.js
index 0453e4740..62c922e2e 100644
--- a/lib/radar-rules.js
+++ b/lib/radar-rules.js
@@ -311,35 +311,6 @@ module.exports = {
},
],
},
- 'dcard.tw': {
- _name: 'Dcard',
- www: [
- {
- title: '首頁帖子-最新',
- docs: 'https://docs.rsshub.app/bbs.html#dcard',
- source: '/f',
- target: '/dcard/posts/latest',
- },
- {
- title: '首頁帖子-熱門',
- docs: 'https://docs.rsshub.app/bbs.html#dcard',
- source: '/f',
- target: '/dcard/posts/popular',
- },
- {
- title: '板塊帖子-最新',
- docs: 'https://docs.rsshub.app/bbs.html#dcard',
- source: '/f/:section',
- target: '/dcard/:section/latest',
- },
- {
- title: '板塊帖子-熱門',
- docs: 'https://docs.rsshub.app/bbs.html#dcard',
- source: '/f/:section',
- target: '/dcard/:section/popular',
- },
- ],
- },
'wegene.com': {
_name: 'WeGene',
www: [
diff --git a/lib/router.js b/lib/router.js
index 88d534d55..b66b4f553 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -1349,7 +1349,7 @@ router.get('/ui-cn/article', lazyloadRouteHandler('./routes/ui-cn/article'));
router.get('/ui-cn/user/:id', lazyloadRouteHandler('./routes/ui-cn/user'));
// Dcard
-router.get('/dcard/:section/:type?', lazyloadRouteHandler('./routes/dcard/section'));
+// router.get('/dcard/:section/:type?', lazyloadRouteHandler('./routes/dcard/section'));
// 北京天文馆每日一图
router.get('/bjp/apod', lazyloadRouteHandler('./routes/bjp/apod'));
diff --git a/lib/v2/dcard/maintainer.js b/lib/v2/dcard/maintainer.js
new file mode 100644
index 000000000..f09e57a9a
--- /dev/null
+++ b/lib/v2/dcard/maintainer.js
@@ -0,0 +1,4 @@
+module.exports = {
+ '/posts/:type?': ['DIYgod'], // alias
+ '/:section/:type?': ['HenryQW'],
+};
diff --git a/lib/v2/dcard/radar.js b/lib/v2/dcard/radar.js
new file mode 100644
index 000000000..da718f52b
--- /dev/null
+++ b/lib/v2/dcard/radar.js
@@ -0,0 +1,31 @@
+module.exports = {
+ 'dcard.tw': {
+ _name: 'Dcard',
+ www: [
+ {
+ title: '首頁帖子-最新',
+ docs: 'https://docs.rsshub.app/bbs.html#dcard',
+ source: '/f',
+ target: '/dcard/posts/latest',
+ },
+ {
+ title: '首頁帖子-熱門',
+ docs: 'https://docs.rsshub.app/bbs.html#dcard',
+ source: '/f',
+ target: '/dcard/posts/popular',
+ },
+ {
+ title: '板塊帖子-最新',
+ docs: 'https://docs.rsshub.app/bbs.html#dcard',
+ source: '/f/:section',
+ target: '/dcard/:section/latest',
+ },
+ {
+ title: '板塊帖子-熱門',
+ docs: 'https://docs.rsshub.app/bbs.html#dcard',
+ source: '/f/:section',
+ target: '/dcard/:section/popular',
+ },
+ ],
+ },
+};
diff --git a/lib/v2/dcard/router.js b/lib/v2/dcard/router.js
new file mode 100644
index 000000000..cc30509f9
--- /dev/null
+++ b/lib/v2/dcard/router.js
@@ -0,0 +1,3 @@
+module.exports = (router) => {
+ router.get('/:section/:type?', require('./section'));
+};
diff --git a/lib/routes/dcard/section.js b/lib/v2/dcard/section.js
similarity index 90%
rename from lib/routes/dcard/section.js
rename to lib/v2/dcard/section.js
index 5131308a7..3b9a0fe7d 100644
--- a/lib/routes/dcard/section.js
+++ b/lib/v2/dcard/section.js
@@ -28,11 +28,9 @@ module.exports = async (ctx) => {
title += '最新';
}
- const response = await got({
- method: 'get',
- url: `${api}&limit=30`,
+ const response = await got(`${api}&limit=30`, {
headers: {
- Referer: link,
+ 'user-agent': 'dcard-web',
},
});
diff --git a/lib/routes/dcard/utils.js b/lib/v2/dcard/utils.js
similarity index 72%
rename from lib/routes/dcard/utils.js
rename to lib/v2/dcard/utils.js
index 33270536d..f79517569 100644
--- a/lib/routes/dcard/utils.js
+++ b/lib/v2/dcard/utils.js
@@ -1,21 +1,20 @@
const got = require('@/utils/got');
+const { parseDate } = require('@/utils/parse-date');
const ProcessFeed = async (list, cache) => {
const result = await Promise.all(
list.map(async (item) => {
- const url = `https://www.dcard.tw/_api/posts/${item.id}`;
+ const url = `https://www.dcard.tw/service/api/v2/posts/${item.id}`;
- const content = await cache.tryGet(`dcard${item.id}`, async () => {
+ const content = await cache.tryGet(`dcard:${item.id}`, async () => {
let response;
// try catch 处理被删除的帖子
try {
- response = await got({
- method: 'get',
- url,
+ response = await got(url, {
headers: {
- Referer: 'https://www.dcard.tw/f',
+ 'user-agent': 'dcard-web',
},
});
@@ -38,11 +37,11 @@ const ProcessFeed = async (list, cache) => {
link: `https://www.dcard.tw/f/${item.forumAlias}/p/${item.id}`,
description: content,
author: item.school || '匿名',
- pubDate: item.createdAt,
- guid: item.id,
+ pubDate: parseDate(item.createdAt),
+ category: [item.forumName, ...item.topics],
};
- return Promise.resolve(single);
+ return single;
})
);