mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-09-01 14:57:14 +08:00
feat(route): add Elastic 中文社区 (#9925)
* feat(route): add Elastic 中文社区 * docs: fix typo * fix: pubDate
This commit is contained in:
+12
@@ -176,6 +176,18 @@ pageClass: routes
|
||||
|
||||
</Route>
|
||||
|
||||
## Elastic 中文社区
|
||||
|
||||
### 发现
|
||||
|
||||
<Route author="nczitzk" example="/elasticsearch-cn" path="/elasticsearch-cn/:params?" :paramsDesc="['分类,可在对应分类页 URL 中找到']">
|
||||
|
||||
如 [Elasticsearch 最新](https://elasticsearch.cn/category-2) 的 URL 为 <https://elasticsearch.cn/category-2>,则分类参数处填写 `category-2`,最后得到路由地址 [`/elasticsearch-cn/category-2`](https://rsshub.app/elasticsearch-cn/category-2)。
|
||||
|
||||
又如 [求职招聘 30 天热门](https://elasticsearch.cn/sort_type-hot\_\_\_\_category-12\__day-30) 的 URL 为 <https://elasticsearch.cn/sort_type-hot____category-12__day-30>,则分类参数处填写 `sort_type-hot____category-12__day-30`,最后得到路由地址 [`/elasticsearch-cn/sort_type-hot____category-12__day-30`](https://rsshub.app/elasticsearch-cn/sort_type-hot\_\_\_\_category-12\__day-30)。
|
||||
|
||||
</Route>
|
||||
|
||||
## eTOLAND
|
||||
|
||||
### 主题贴
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
const timezone = require('@/utils/timezone');
|
||||
const { parseDate, parseRelativeDate } = require('@/utils/parse-date');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const params = ctx.params.params ?? '';
|
||||
|
||||
const rootUrl = 'https://elasticsearch.cn';
|
||||
const currentUrl = `${rootUrl}${params ? `/${params}` : ''}`;
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
let items = $('.aw-question-content')
|
||||
.toArray()
|
||||
.map((item) => {
|
||||
item = $(item);
|
||||
|
||||
const a = item.find('h4 a');
|
||||
const pubDate = item.find('span.text-color-999').not('.pull-right').first().text().split('•').pop().trim();
|
||||
|
||||
return {
|
||||
title: a.text(),
|
||||
link: a.attr('href'),
|
||||
author: item.find('.aw-user-name').text(),
|
||||
pubDate: timezone(/\d{4}-\d{2}-\d{2} \d{2}:\d{2}/.test(pubDate) ? parseDate(pubDate) : parseRelativeDate(pubDate), +8),
|
||||
};
|
||||
});
|
||||
|
||||
items = await Promise.all(
|
||||
items.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content('.markitup-box').first().html();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = {
|
||||
'/:params?': ['nczitzk'],
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
module.exports = {
|
||||
'elasticsearch.cn': {
|
||||
_name: 'Elastic 中文社区',
|
||||
'.': [
|
||||
{
|
||||
title: '发现',
|
||||
docs: 'https://docs.rsshub.app/bbs.html#elastic-zhong-wen-she-qu-fa-xian',
|
||||
source: ['/:params', '/'],
|
||||
target: '/elasticsearch-cn/:params',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = function (router) {
|
||||
router.get('/:params?', require('./index'));
|
||||
};
|
||||
Reference in New Issue
Block a user