mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-04 11:07:54 +08:00
feat(route): add slowmist news (#10044)
* feat(route): add slowmist news * feat(utils): remove useless ul for code section * docs: add slowmist news route docs * docs(quick-start): new router under /lib/v2 * test(utils): add test fixArticleContent for new wechat-mp code * feat(router): update radar source of slowmist
This commit is contained in:
@@ -21,11 +21,11 @@ sidebar: auto
|
|||||||
|
|
||||||
### 添加脚本路由
|
### 添加脚本路由
|
||||||
|
|
||||||
在 [/lib/router.js](https://github.com/DIYgod/RSSHub/blob/master/lib/router.js) 里添加路由
|
在 [/lib/v2/routes/](https://github.com/DIYgod/RSSHub/tree/master/lib/routes) 中创建对应路由路径,并在 `/lib/v2/routes/:path/router.js` 中添加路由
|
||||||
|
|
||||||
### 编写脚本
|
### 编写脚本
|
||||||
|
|
||||||
在 [/lib/routes/](https://github.com/DIYgod/RSSHub/tree/master/lib/routes) 中的路由对应路径下创建新的 js 脚本:
|
在 [/lib/v2/routes/](https://github.com/DIYgod/RSSHub/tree/master/lib/routes) 中的路由对应路径下创建新的 js 脚本:
|
||||||
|
|
||||||
#### 获取源数据
|
#### 获取源数据
|
||||||
|
|
||||||
@@ -493,7 +493,7 @@ ctx.state.data = {
|
|||||||
|
|
||||||
### 编写规则
|
### 编写规则
|
||||||
|
|
||||||
在 [/assets/radar-rules.js](https://github.com/DIYgod/RSSHub/blob/master/assets/radar-rules.js) 里添加规则
|
在 [/lib/v2/routes/](https://github.com/DIYgod/RSSHub/tree/master/lib/routes) 的对应路由下创建 `radar.js` 并添加规则
|
||||||
|
|
||||||
下面说明中会用到的简化的规则:
|
下面说明中会用到的简化的规则:
|
||||||
|
|
||||||
|
|||||||
@@ -2666,6 +2666,18 @@ column 为 third 时可选的 category:
|
|||||||
|
|
||||||
</Route>
|
</Route>
|
||||||
|
|
||||||
|
## 慢雾科技
|
||||||
|
|
||||||
|
### 动态
|
||||||
|
|
||||||
|
<Route author="AtlasQuan" example="/slowmist/research" path="/slowmist/:type?" :paramsDesc="['分类,见下表,默认为公司新闻']">
|
||||||
|
|
||||||
|
| 公司新闻 | 漏洞披露 | 技术研究 |
|
||||||
|
| ---- | ---- | -------- |
|
||||||
|
| news | vul | research |
|
||||||
|
|
||||||
|
</Route>
|
||||||
|
|
||||||
## 梅花网
|
## 梅花网
|
||||||
|
|
||||||
### 作品
|
### 作品
|
||||||
|
|||||||
@@ -104,6 +104,14 @@ const fixArticleContent = (html, skipImg = false) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// add breaks in code section
|
||||||
|
$('code').each((_, code) => {
|
||||||
|
$('<br>').insertAfter(code);
|
||||||
|
});
|
||||||
|
|
||||||
|
// clear line index tags in code section
|
||||||
|
$('.code-snippet__line-index').remove();
|
||||||
|
|
||||||
// fix single picture article
|
// fix single picture article
|
||||||
// example: https://mp.weixin.qq.com/s/4p5YmYuASiQSYFiy7KqydQ
|
// example: https://mp.weixin.qq.com/s/4p5YmYuASiQSYFiy7KqydQ
|
||||||
$('script').each((_, script) => {
|
$('script').each((_, script) => {
|
||||||
@@ -186,7 +194,6 @@ const fetchArticle = async (ctx, url, bypassHostCheck = false) => {
|
|||||||
let summary = $('meta[name=description]').attr('content');
|
let summary = $('meta[name=description]').attr('content');
|
||||||
summary = summary !== title ? summary : '';
|
summary = summary !== title ? summary : '';
|
||||||
let description = fixArticleContent($('#js_content'));
|
let description = fixArticleContent($('#js_content'));
|
||||||
|
|
||||||
// No article get or article is too short, try the original url
|
// No article get or article is too short, try the original url
|
||||||
const originalUrl = detectOriginalArticleUrl($);
|
const originalUrl = detectOriginalArticleUrl($);
|
||||||
if (originalUrl) {
|
if (originalUrl) {
|
||||||
@@ -211,7 +218,6 @@ const fetchArticle = async (ctx, url, bypassHostCheck = false) => {
|
|||||||
|
|
||||||
let mpName = $('.profile_nickname').first().text();
|
let mpName = $('.profile_nickname').first().text();
|
||||||
mpName = mpName && mpName.trim();
|
mpName = mpName && mpName.trim();
|
||||||
|
|
||||||
return { title, author, description, summary, pubDate, mpName, link: url };
|
return { title, author, description, summary, pubDate, mpName, link: url };
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
13
lib/v2/slowmist/radar.js
Normal file
13
lib/v2/slowmist/radar.js
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
module.exports = {
|
||||||
|
'slowmist.com': {
|
||||||
|
_name: '慢雾科技 SLOWMIST',
|
||||||
|
'.': [
|
||||||
|
{
|
||||||
|
title: '动态',
|
||||||
|
docs: 'https://docs.rsshub.app/new-media.html#man-wu-ke-ji',
|
||||||
|
source: ['/zh/news.html'],
|
||||||
|
target: '/slowmist/:type?',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
3
lib/v2/slowmist/router.js
Normal file
3
lib/v2/slowmist/router.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = function (router) {
|
||||||
|
router.get('/:type?', require('./slowmist'));
|
||||||
|
};
|
||||||
39
lib/v2/slowmist/slowmist.js
Normal file
39
lib/v2/slowmist/slowmist.js
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
const got = require('@/utils/got');
|
||||||
|
const { parseDate } = require('@/utils/parse-date');
|
||||||
|
const baseUrl = 'https://www.slowmist.com';
|
||||||
|
const { finishArticleItem } = require('@/utils/wechat-mp');
|
||||||
|
|
||||||
|
module.exports = async (ctx) => {
|
||||||
|
let type = ctx.params.type;
|
||||||
|
|
||||||
|
let title = '慢雾科技 - ';
|
||||||
|
if (type === 'news') {
|
||||||
|
title += '公司新闻';
|
||||||
|
} else if (type === 'vul') {
|
||||||
|
title += '漏洞披露';
|
||||||
|
} else if (type === 'research') {
|
||||||
|
title += '技术研究';
|
||||||
|
} else {
|
||||||
|
type = 'news';
|
||||||
|
title += '公司新闻';
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = `${baseUrl}/api/get_list?type=${type}`;
|
||||||
|
|
||||||
|
const response = await got(url);
|
||||||
|
|
||||||
|
let items = (response.data.data || []).map((item) => ({
|
||||||
|
title: item.title,
|
||||||
|
link: item.url,
|
||||||
|
description: item.desc,
|
||||||
|
pubDate: parseDate(item.date),
|
||||||
|
}));
|
||||||
|
|
||||||
|
items = await Promise.all(items.map((item) => finishArticleItem(ctx, item)));
|
||||||
|
|
||||||
|
ctx.state.data = {
|
||||||
|
title,
|
||||||
|
link: url,
|
||||||
|
item: items,
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -24,8 +24,28 @@ describe('wechat-mp', () => {
|
|||||||
it('fixArticleContent', () => {
|
it('fixArticleContent', () => {
|
||||||
const divHeader = '<div class="rich_media_content " id="js_content">';
|
const divHeader = '<div class="rich_media_content " id="js_content">';
|
||||||
const divFooter = '</div>';
|
const divFooter = '</div>';
|
||||||
|
const codeSection =
|
||||||
|
'<section class="code-snippet__fix code-snippet__js">' +
|
||||||
|
'<ul class="code-snippet__line-index code-snippet__js">' +
|
||||||
|
'<li></li><li></li><li></li>' +
|
||||||
|
'</ul >' +
|
||||||
|
'<pre class="code-snippet__js">' +
|
||||||
|
'<code><span class="code-snippet_outer">Line1 {</span></code>' +
|
||||||
|
'<code><span class="code-snippet__keyword">Line2</span></code>' +
|
||||||
|
'<code><span class="code-snippet_outer">Line3 }</span></code>' +
|
||||||
|
'</pre></section>';
|
||||||
|
const expectedCodeSection =
|
||||||
|
'<p class="code-snippet__fix code-snippet__js">' +
|
||||||
|
'<pre class="code-snippet__js">' +
|
||||||
|
'<code><span class="code-snippet_outer">Line1 {</span></code>' +
|
||||||
|
'<br>' +
|
||||||
|
'<code><span class="code-snippet__keyword">Line2</span></code>' +
|
||||||
|
'<br>' +
|
||||||
|
'<code><span class="code-snippet_outer">Line3 }</span></code>' +
|
||||||
|
'<br>' +
|
||||||
|
'</pre></p>';
|
||||||
const htmlSection =
|
const htmlSection =
|
||||||
|
codeSection +
|
||||||
'<section>test</section>' +
|
'<section>test</section>' +
|
||||||
'<section><p>test</p></section>' +
|
'<section><p>test</p></section>' +
|
||||||
'<section><div>test</div></section>' +
|
'<section><div>test</div></section>' +
|
||||||
@@ -34,7 +54,8 @@ describe('wechat-mp', () => {
|
|||||||
'<p>test</p>' +
|
'<p>test</p>' +
|
||||||
'<div><p>test</p></div>' +
|
'<div><p>test</p></div>' +
|
||||||
'<script>const test = "test"</script>';
|
'<script>const test = "test"</script>';
|
||||||
const expectedHtmlSection = '<p>test</p>' + '<div><p>test</p></div>' + '<div><div>test</div></div>' + '<div><div><p>test</p></div></div>' + '<div><div><p>test</p></div></div>' + '<p>test</p>' + '<div><p>test</p></div>';
|
const expectedHtmlSection =
|
||||||
|
expectedCodeSection + '<p>test</p>' + '<div><p>test</p></div>' + '<div><div>test</div></div>' + '<div><div><p>test</p></div></div>' + '<div><div><p>test</p></div></div>' + '<p>test</p>' + '<div><p>test</p></div>';
|
||||||
let $ = cheerio.load(divHeader + htmlSection + divFooter);
|
let $ = cheerio.load(divHeader + htmlSection + divFooter);
|
||||||
expect(fixArticleContent(htmlSection)).toBe(expectedHtmlSection);
|
expect(fixArticleContent(htmlSection)).toBe(expectedHtmlSection);
|
||||||
expect(fixArticleContent($('div#js_content.rich_media_content'))).toBe(expectedHtmlSection);
|
expect(fixArticleContent($('div#js_content.rich_media_content'))).toBe(expectedHtmlSection);
|
||||||
|
|||||||
Reference in New Issue
Block a user