feat: 增加设计学院研创、后浪模块;支持获取微信文章内容;修复重复条目bug (#10994)

* 南京艺术学院研究生院

* Update lib/v2/nua/gra.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/nua/gra.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/nua/gra.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/nua/radar.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/nua/radar.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/nua/gra.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update lib/v2/nua/gra.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update docs/university.md

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* Update docs/university.md

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* 优化代码

* 优化

* update

* 补充南京艺术学院

* fix

* fix

* fix

* 更新南京艺术学院数据源。

* 更新南京艺术学院数据源。

* fix

* fix

* update

* fix doc

* fix

* Update lib/v2/nua/radar.js

Co-authored-by: Tony <TonyRL@users.noreply.github.com>

* fix: yarn.lock permission

* style: auto format

* fix double fetch same page

* Update dc.js

* Revert "Merge branch 'master' of https://github.com/evnydd0sf/RSS-Hub"

This reverts commit dd56f9469b, reversing
changes made to d900050eb8.

* fix

* Revert "fix"

This reverts commit 820ff88120.

* Revert "Revert "Merge branch 'master' of https://github.com/evnydd0sf/RSS-Hub""

This reverts commit ce67e0b53c.

* 增加微信公众号解析引导。

* 修正url

* 适配微信公众号内容。

* 适配站内文章、微信公号号文章和未知文章引导。

* Update wechat-mp.js

* fix fetch wechat bug

* 增加设计学院研创、后浪模块

* bugfix

* Revert "Merge branch 'DIYgod:master' into master"

This reverts commit 102cb48db6, reversing
changes made to ccac4be518.

* Update university.md

* Revert "Revert "Merge branch 'DIYgod:master' into master""

This reverts commit c8841910b8.

* fix fetch listname

* fix: switch default case
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
evnydd0sf
2022-10-05 21:32:49 +08:00
committed by GitHub
parent 4dbadfe2b8
commit fdc59d2d65
7 changed files with 73 additions and 41 deletions

View File

@@ -2116,14 +2116,16 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS
### 设计学院
<Route author="evnydd0sf" example="/nua/dc/346" path="/nua/dc/:type" :paramsDesc="['新闻模块,见下表']" radar="1">
<Route author="evnydd0sf" example="/nua/dc/news" path="/nua/dc/:type" :paramsDesc="['新闻模块,见下表']" radar="1">
| 新闻模块 | 参数 |
| ---------- | ------- |
| ---------------------- | ---------- |
| 学院新闻 NEWS | news |
| 教学 TEACH | teach |
| 展览 EXHIBITION | exhibition |
| 研创 RESEARCH & CREATION | rc |
| 项目 PROJECT | project |
| 党团 PARTY | party |
| 后浪 YOUTH | youth |
</Route>
@@ -2132,11 +2134,10 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS
<Route author="evnydd0sf" example="/nua/gra/1959" path="/nua/gra/:type" :paramsDesc="['新闻模块,见下表']" radar="1">
| 新闻模块 | 参数 |
| ----- | ---- |
| ---- | ---- |
| 招生工作 | 1959 |
| 培养工作 | 1962 |
| 学位工作 | 1958 |
| 思政与管理 | 1960 |
</Route>

View File

@@ -7,6 +7,7 @@
* lib/v2/gzh360
* lib/v2/pku/nsd/gd
* lib/v2/sdu/cs
* lib/v2/nua/utils
*
* If your new route is not in the above folders, please add it to the list.
*

View File

@@ -1,5 +1,3 @@
// const got = require('@/utils/got');
// const cheerio = require('cheerio');
const util = require('./utils');
module.exports = async (ctx) => {
@@ -19,7 +17,7 @@ module.exports = async (ctx) => {
artiContent = '.article';
webPageName = 'li.pre35.left .big_title';
break;
case 'teach':
case 'exhibition':
listName = 'li.pre65.right li.effects';
listDate = '.date';
artiContent = '.article';
@@ -31,18 +29,30 @@ module.exports = async (ctx) => {
artiContent = '.article';
webPageName = 'ul.center .big_title';
break;
case 'rc':
listName = 'div.pre65.left p.small_content_2';
listDate = '.date';
artiContent = '.article';
webPageName = 'div.pre65.left.is-inview .big_title';
break;
case 'party':
listName = 'div.pre35.right li.party_list';
listDate = '.date';
artiContent = '.article';
webPageName = 'div.pre35.right .big_title';
break;
case 'youth':
listName = 'ul.works_list p.small_content_2.viewpoint';
listDate = '.date';
artiContent = '.article';
webPageName = 'ul.screen_4 .big_title';
break;
default:
throw Error(`暂不支持对${type}的订阅`);
}
const items = await util.ProcessList(baseUrl, baseUrl, listName, listDate, webPageName);
const results = await util.ProcessFeed(items[0], artiContent, ctx.cache);
const results = await util.ProcessFeed(items[0], artiContent, ctx);
ctx.state.data = {
title: 'NUA-设计学院-' + items[1],

View File

@@ -10,7 +10,7 @@ module.exports = async (ctx) => {
const webPageName = '.col_title';
const items = await util.ProcessList(newsUrl, baseUrl, listName, listDate, webPageName);
const results = await util.ProcessFeed(items[0], artiContent, ctx.cache);
const results = await util.ProcessFeed(items[0], artiContent, ctx);
ctx.state.data = {
title: 'NUA-研究生处-' + items[1],

View File

@@ -11,7 +11,7 @@ module.exports = async (ctx) => {
const artiContent = '.read';
const items = await util.ProcessList(newsUrl, baseUrl, listName, listDate, webPageName);
const results = await util.ProcessFeed(items[0], artiContent, ctx.cache);
const results = await util.ProcessFeed(items[0], artiContent, ctx);
ctx.state.data = {
title: 'NUA-' + items[1],

View File

@@ -11,7 +11,7 @@ module.exports = async (ctx) => {
const artiContent = '.read';
const items = await util.ProcessList(newsUrl, baseUrl, listName, listDate, webPageName);
const results = await util.ProcessFeed(items[0], artiContent, ctx.cache);
const results = await util.ProcessFeed(items[0], artiContent, ctx);
ctx.state.data = {
title: 'NUA-双馨网-' + items[1],

View File

@@ -2,6 +2,25 @@ const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const { fetchArticle } = require('@/utils/wechat-mp');
const pageType = (href) => {
if (!href.startsWith('http')) {
return 'in-nua';
}
const url = new URL(href);
if (url.hostname === 'mp.weixin.qq.com') {
return 'wechat-mp';
} else if (url.hostname === 'www.nua.edu.cn') {
return 'nua';
} else {
return 'unknown';
}
};
function arti_link(text, href) {
return `<a href="${href}">${text}</a>`;
}
async function ProcessList(newsUrl, baseUrl, listName, listDate, webPageName) {
const result = await got(newsUrl, {
@@ -13,43 +32,44 @@ async function ProcessList(newsUrl, baseUrl, listName, listDate, webPageName) {
const pageName = $(webPageName).text();
let artiLink;
const items = $(listName)
.toArray()
.map((item) => {
item = $(item);
if (item.find('a').attr('href').includes('http')) {
artiLink = item.find('a').attr('href');
} else {
artiLink = baseUrl + item.find('a').attr('href');
}
const href = $(item).find('a').attr('href');
const type = pageType(href);
return {
link: artiLink,
link: type === 'in-nua' ? baseUrl + href : href,
title: item.find('a').attr('title'),
pubDate: timezone(parseDate(item.find(listDate).first().text(), 'YYYY-MM-DD'), +8),
type,
};
});
return [items, pageName];
}
const ProcessFeed = async (items, artiContent, cache) =>
const ProcessFeed = async (items, artiContent, ctx) =>
await Promise.all(
items.map((item) =>
cache.tryGet(item.link, async () => {
const result = await got(item.link, {
https: {
rejectUnauthorized: false,
},
});
ctx.cache.tryGet(item.link, async () => {
switch (item.type) {
case 'in-nua' || 'nua':
// eslint-disable-next-line no-case-declarations
const result = await got(item.link, { https: { rejectUnauthorized: false } });
// eslint-disable-next-line no-case-declarations
const $ = cheerio.load(result.data);
item.author = $('.arti_publisher').text() + ' ' + $('.arti_views').text();
item.description = $(artiContent).html();
return item;
case 'wechat-mp':
return fetchArticle(ctx, item.link);
case 'unknown':
default:
item.description = `暂不支持解析该内容,请点击 ${arti_link('原文', item.link)}`;
return item;
}
})
)
);