Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(route): add 电子工程专辑芯语 #12939

Merged
merged 2 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/new-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -2197,6 +2197,30 @@ area 分区选项

<Route author="TonyRL" example="/agirls/topic_list" path="/agirls/topic_list" radar="1" rssbud="1"/>

## 电子工程专辑

### 芯语

<Route author="nczitzk" example="/eet-china/mp" path="/eet-china/mp/:category?" :paramsDesc="['分类,见下表,默认为最新']">

| 最新 | 半导体 | 通信网络 | 消费电子/手机 | 汽车电子 |
| ---- | ------ | -------- | ------------- | -------- |
| | 1 | 2 | 3 | 4 |

| 物联网 | 工控 | 硬件设计 | 嵌入式/FPGA | 电源/能源 |
| ------ | ---- | -------- | ----------- | --------- |
| 5 | 6 | 7 | 8 | 9 |

| 测试测量 | 人工智能/机器人 | 科技前沿 | 供应链 | 工程师职场 |
| -------- | --------------- | -------- | ------ | ---------- |
| 10 | 11 | 12 | 13 | 14 |

</Route>

### 芯语标签

<Route author="nczitzk" example="/eet-china/mp/tags/36806" path="/eet-china/mp/tags/:id" :paramsDesc="['标签 id,可在对应标签页中找到']"/>

## 丁香园

### 新冠疫苗实时动态
Expand Down
4 changes: 4 additions & 0 deletions lib/v2/eet-china/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
'/mp/tags/:id': ['nczitzk'],
'/mp/:category?': ['nczitzk'],
};
10 changes: 10 additions & 0 deletions lib/v2/eet-china/mp/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { rootUrl, ProcessItems } = require('./util');

module.exports = async (ctx) => {
const { category = '' } = ctx.params;
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30;

const currentUrl = new URL(`mp${category ? `/c${category}` : ''}`, rootUrl).href;

ctx.state.data = await ProcessItems(limit, currentUrl, ctx.cache.tryGet);
};
10 changes: 10 additions & 0 deletions lib/v2/eet-china/mp/tags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { rootUrl, ProcessItems } = require('./util');

module.exports = async (ctx) => {
const { id } = ctx.params;
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30;

const currentUrl = new URL(`mp/tags/${id}`, rootUrl).href;

ctx.state.data = await ProcessItems(limit, currentUrl, ctx.cache.tryGet);
};
67 changes: 67 additions & 0 deletions lib/v2/eet-china/mp/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');

const rootUrl = 'https://www.eet-china.com';

module.exports = {
rootUrl,
ProcessItems: async (limit, currentUrl, tryGet) => {
const { data: response } = await got(currentUrl);

const $ = cheerio.load(response);

let items = $('div.swiper-con a, div.new-title a, h1.new-title a')
.toArray()
.map((item) => {
item = $(item);

return {
title: item.text().trim(),
link: item.prop('href'),
};
})
.filter((item) => /^(?!.*specialcolumn\.php).*$/.test(item.link))
.slice(0, limit);

items = await Promise.all(
items.map((item) =>
tryGet(item.link, async () => {
const { data: detailResponse } = await got(item.link);

const content = cheerio.load(detailResponse);

const relevantData = content('div.new-relevant span.hidden-xs');
const upvotes = relevantData.eq(1).text();
const comments = relevantData.eq(2).text();

item.title = content('h1.detail-title').text();
item.description = content('div.article-con').html();
item.author = content('a.write').first().text();
item.category = content('meta[name="keywords"]').prop('content')?.split(',') ?? undefined;
item.pubDate = timezone(parseDate(content('div.new-relevant span').first().text()), +8);
item.upvotes = upvotes ? parseInt(upvotes.replace(/点赞/, ''), 10) : 0;
item.comments = comments ? parseInt(comments.replace(/评论/, ''), 10) : 0;

return item;
})
)
);

const icon = new URL($('div.logo-mianbaoban a img').prop('src'), rootUrl).href;

return {
item: items,
title: `面包芯语 - ${$('li.active').text() || $('div.thetitle').first().text()}`,
link: currentUrl,
description: $('meta[name="description"]').prop('content'),
language: 'zh-cn',
image: new URL($('div.logo-xinyu a img').prop('src'), rootUrl).href,
icon,
logo: icon,
subtitle: $('meta[name="keywords"]').prop('content'),
author: '电子工程专辑',
};
},
};
24 changes: 24 additions & 0 deletions lib/v2/eet-china/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
'eet-china.com': {
_name: '电子工程专辑',
'.': [
{
title: '芯语',
docs: 'https://docs.rsshub.app/new-media.html#dian-zi-gong-cheng-zhuan-ji-xin-yu',
source: ['/mp', '/'],
target: (params, url) => {
url = new URL(url);
const path = url.href.match(/\.com\/mp(.*?)/)[1];

return `/eet-china/mp${path ? `/${path}` : ''}`;
},
},
{
title: '芯语 - 标签',
docs: 'https://docs.rsshub.app/new-media.html#dian-zi-gong-cheng-zhuan-ji-xin-yu-biao-qian',
source: ['/mp/tags/:id', '/'],
target: '/eet-china/mp/tags/:id',
},
],
},
};
4 changes: 4 additions & 0 deletions lib/v2/eet-china/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = function (router) {
router.get('/mp/tags/:id', require('./mp/tags'));
router.get('/mp/:category?', require('./mp'));
};