forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add 电子工程专辑芯语 (DIYgod#12939)
* feat(route): add 电子工程专辑芯语 * fix radar
- Loading branch information
Showing
7 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
'/mp/tags/:id': ['nczitzk'], | ||
'/mp/:category?': ['nczitzk'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: '电子工程专辑', | ||
}; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); | ||
}; |