diff --git a/docs/new-media.md b/docs/new-media.md
index d2f089aca..bf7debf1a 100644
--- a/docs/new-media.md
+++ b/docs/new-media.md
@@ -659,7 +659,7 @@ Tag
### 话题
-
+
## IT 之家
diff --git a/lib/router.js b/lib/router.js
index 0788848d2..be86f61ee 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -1466,8 +1466,8 @@ router.get('/zucc/cssearch/latest/:webVpn/:key', lazyloadRouteHandler('./routes/
router.get('/ccnu/career', lazyloadRouteHandler('./routes/universities/ccnu/career'));
// Infoq
-router.get('/infoq/recommend', lazyloadRouteHandler('./routes/infoq/recommend'));
-router.get('/infoq/topic/:id', lazyloadRouteHandler('./routes/infoq/topic'));
+// router.get('/infoq/recommend', lazyloadRouteHandler('./routes/infoq/recommend'));
+// router.get('/infoq/topic/:id', lazyloadRouteHandler('./routes/infoq/topic'));
// checkee
router.get('/checkee/:dispdate', lazyloadRouteHandler('./routes/checkee/index'));
diff --git a/lib/v2/infoq/maintainer.js b/lib/v2/infoq/maintainer.js
new file mode 100644
index 000000000..2538882c7
--- /dev/null
+++ b/lib/v2/infoq/maintainer.js
@@ -0,0 +1,4 @@
+module.exports = {
+ '/recommend': ['brilon'],
+ '/topic/:id': ['brilon'],
+};
diff --git a/lib/v2/infoq/radar.js b/lib/v2/infoq/radar.js
new file mode 100644
index 000000000..e8caa6ac6
--- /dev/null
+++ b/lib/v2/infoq/radar.js
@@ -0,0 +1,19 @@
+module.exports = {
+ 'infoq.cn': {
+ _name: 'InfoQ 中文',
+ '.': [
+ {
+ title: '推荐',
+ docs: 'https://docs.rsshub.app/new-media.html#infoq-zhong-wen',
+ source: ['/'],
+ target: '/infoq/recommend',
+ },
+ {
+ title: '话题',
+ docs: 'https://docs.rsshub.app/new-media.html#infoq-zhong-wen',
+ source: ['/topic/:id'],
+ target: '/infoq/topic/:id',
+ },
+ ],
+ },
+};
diff --git a/lib/routes/infoq/recommend.js b/lib/v2/infoq/recommend.js
similarity index 75%
rename from lib/routes/infoq/recommend.js
rename to lib/v2/infoq/recommend.js
index 3bfed9887..9296f174b 100644
--- a/lib/routes/infoq/recommend.js
+++ b/lib/v2/infoq/recommend.js
@@ -5,14 +5,12 @@ module.exports = async (ctx) => {
const apiUrl = 'https://www.infoq.cn/public/v1/my/recommond';
const pageUrl = 'https://www.infoq.cn';
- const resp = await got({
- method: 'post',
- url: apiUrl,
+ const resp = await got.post(apiUrl, {
headers: {
Referer: pageUrl,
},
json: {
- size: 5,
+ size: ctx.query.limit ? Number(ctx.query.limit) : 30,
},
});
@@ -20,9 +18,8 @@ module.exports = async (ctx) => {
const items = await utils.ProcessFeed(data, ctx.cache);
ctx.state.data = {
- title: 'InfoQ推荐',
+ title: 'InfoQ 推荐',
link: pageUrl,
- description: 'InfoQ推荐',
item: items,
};
};
diff --git a/lib/v2/infoq/router.js b/lib/v2/infoq/router.js
new file mode 100644
index 000000000..3d0991915
--- /dev/null
+++ b/lib/v2/infoq/router.js
@@ -0,0 +1,4 @@
+module.exports = (router) => {
+ router.get('/recommend', require('./recommend'));
+ router.get('/topic/:id', require('./topic'));
+};
diff --git a/lib/routes/infoq/topic.js b/lib/v2/infoq/topic.js
similarity index 64%
rename from lib/routes/infoq/topic.js
rename to lib/v2/infoq/topic.js
index 004adcce8..601721400 100644
--- a/lib/routes/infoq/topic.js
+++ b/lib/v2/infoq/topic.js
@@ -2,32 +2,28 @@ const got = require('@/utils/got');
const utils = require('./utils');
module.exports = async (ctx) => {
- const paramId = parseInt(ctx.params.id);
+ const paramId = ctx.params.id;
const apiUrl = 'https://www.infoq.cn/public/v1/article/getList';
const infoUrl = 'https://www.infoq.cn/public/v1/topic/getInfo';
const pageUrl = `https://www.infoq.cn/topic/${paramId}`;
- const info = await got({
- method: 'post',
- url: infoUrl,
+ const infoBody = isNaN(paramId) ? { alias: paramId } : { id: parseInt(paramId) };
+
+ const info = await got.post(infoUrl, {
headers: {
Referer: pageUrl,
},
- json: {
- id: paramId,
- },
+ json: infoBody,
});
const topicName = info.data.data.name;
const type = info.data.data.type;
- const resp = await got({
- method: 'post',
- url: apiUrl,
+ const resp = await got.post(apiUrl, {
headers: {
Referer: pageUrl,
},
json: {
- size: 5,
+ size: ctx.query.limit ? Number(ctx.query.limit) : 30,
type,
id: paramId,
},
@@ -37,9 +33,10 @@ module.exports = async (ctx) => {
const items = await utils.ProcessFeed(data, ctx.cache);
ctx.state.data = {
- title: `InfoQ话题 - ${topicName}`,
+ title: `InfoQ 话题 - ${topicName}`,
+ description: info.data.data.desc,
+ image: info.data.data.cover,
link: pageUrl,
- description: `InfoQ话题 - ${topicName}`,
item: items,
};
};
diff --git a/lib/routes/infoq/utils.js b/lib/v2/infoq/utils.js
similarity index 81%
rename from lib/routes/infoq/utils.js
rename to lib/v2/infoq/utils.js
index 5bdddf268..468030bbb 100644
--- a/lib/routes/infoq/utils.js
+++ b/lib/v2/infoq/utils.js
@@ -1,4 +1,5 @@
const got = require('@/utils/got');
+const { parseDate } = require('@/utils/parse-date');
const ProcessFeed = async (list, cache) => {
const detailUrl = 'https://www.infoq.cn/public/v1/article/getDetail';
@@ -8,9 +9,7 @@ const ProcessFeed = async (list, cache) => {
const uuid = e.uuid;
const single = await cache.tryGet(uuid, async () => {
const link = `https://www.infoq.cn/article/${uuid}`;
- const resp = await got({
- method: 'post',
- url: detailUrl,
+ const resp = await got.post(detailUrl, {
headers: {
Referer: link,
},
@@ -21,19 +20,19 @@ const ProcessFeed = async (list, cache) => {
const data = resp.data.data;
const author = data.author ? data.author.map((p) => p.nickname).join(',') : data.no_author;
- const pubDate = new Date();
- pubDate.setTime(data.publish_time);
+ const category = e.topic.map((t) => t.name).concat(e.label.map((l) => l.name));
return {
title: data.article_title,
description: parseContent(data.content),
- pubDate,
+ pubDate: parseDate(e.publish_time, 'x'),
+ category,
author,
link,
};
});
- return Promise.resolve(single);
+ return single;
})
);
@@ -67,9 +66,13 @@ const parseToSimpleTexts = (content) =>
return `
`;
},
codeblock: () => {
- const lang = i.attrs.lang;
- const code = parseToSimpleText(i.content);
- return `${code}`;
+ if (i.content) {
+ const lang = i.attrs.lang;
+ const code = parseToSimpleText(i.content);
+ return `${code}`;
+ } else {
+ return '';
+ }
},
link: () => {
const href = i.attrs.href;