Skip to content

Commit

Permalink
feat(route): add 墨天轮 (DIYgod#13916)
Browse files Browse the repository at this point in the history
Co-authored-by: fyoylf <fyoylf@gmail.com>
  • Loading branch information
yueneiqi and dboylf authored Nov 30, 2023
1 parent f3bf25f commit 9bfb866
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/v2/modb/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/topic/:id': ['yueneiqi'],
};
13 changes: 13 additions & 0 deletions lib/v2/modb/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'modb.pro': {
_name: '墨天轮',
'.': [
{
title: '合辑',
docs: 'https://docs.rsshub.app/routes/programming#mo-tian-lun',
source: ['/', '/topic/:id'],
target: (params) => `/modb/topic/${params.id}`,
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/modb/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/topic/:id', require('./topic'));
};
59 changes: 59 additions & 0 deletions lib/v2/modb/topic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const cheerio = require('cheerio');
const got = require('@/utils/got');
const logger = require('@/utils/logger');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');

module.exports = async (ctx) => {
const baseUrl = 'https://www.modb.pro';
const topicId = ctx.params.id;
const response = await got({
url: `${baseUrl}/api/columns/getKnowledge`,
searchParams: {
pageNum: 1,
pageSize: 20,
columnId: topicId,
},
}).json();
const list = response.list.map((item) => {
let doc = {};
let baseLink = {};
switch (item.type) {
case 0:
doc = item.knowledge;
baseLink = `${baseUrl}/db`;
break;
case 1:
doc = item.dbDoc;
baseLink = `${baseUrl}/doc`;
break;
default:
logger.error(`unknown type ${item.type}`);
}

return {
title: doc.title,
link: `${baseLink}/${item.rid}`,
pubDate: timezone(parseDate(item.createdTime), +8),
author: doc.createdByName,
category: doc.tags,
};
});

const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = cheerio.load(response);
item.description = $('div.editor-content-styl.article-style').first().html();
return item;
})
)
);

ctx.state.data = {
title: '墨天轮合辑',
link: `${baseUrl}/topic/${topicId}`,
item: items,
};
};
6 changes: 6 additions & 0 deletions website/docs/routes/programming.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,12 @@ Stay up to date on the latest React news, tutorials, resources, and more. Delive

<Route author="youzipi" example="/meituan/open/announce" path="/meituan/open/announce"/>

## 墨天轮 {#mo-tian-lun}

### 合辑 {#mo-tian-lun-he-ji}

<Route author="yueneiqi" example="/modb/topic/44158" path="/modb/topic/:id" paramsDesc={['合辑序号']} radar="1" />

## 平安银河实验室 {#ping-an-yin-he-shi-yan-shi}

### posts {#ping-an-yin-he-shi-yan-shi-posts}
Expand Down

0 comments on commit 9bfb866

Please sign in to comment.