From fdc59d2d6519947e4c8cc2c386ed491455930a3f Mon Sep 17 00:00:00 2001 From: evnydd0sf Date: Wed, 5 Oct 2022 21:32:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E5=AD=A6=E9=99=A2=E7=A0=94=E5=88=9B=E3=80=81=E5=90=8E=E6=B5=AA?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=EF=BC=9B=E6=94=AF=E6=8C=81=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=96=87=E7=AB=A0=E5=86=85=E5=AE=B9=EF=BC=9B?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=87=8D=E5=A4=8D=E6=9D=A1=E7=9B=AEbug=20(#1?= =?UTF-8?q?0994)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 南京艺术学院研究生院 * Update lib/v2/nua/gra.js Co-authored-by: Tony * Update lib/v2/nua/gra.js Co-authored-by: Tony * Update lib/v2/nua/gra.js Co-authored-by: Tony * Update lib/v2/nua/radar.js Co-authored-by: Tony * Update lib/v2/nua/radar.js Co-authored-by: Tony * Update lib/v2/nua/gra.js Co-authored-by: Tony * Update lib/v2/nua/gra.js Co-authored-by: Tony * Update docs/university.md Co-authored-by: Tony * Update docs/university.md Co-authored-by: Tony * 优化代码 * 优化 * update * 补充南京艺术学院 * fix * fix * fix * 更新南京艺术学院数据源。 * 更新南京艺术学院数据源。 * fix * fix * update * fix doc * fix * Update lib/v2/nua/radar.js Co-authored-by: Tony * 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 dd56f9469b5b2462d482c202ae798b3f159f243e, reversing changes made to d900050eb8271d0f566070eb58c2c9d87ccd6e53. * fix * Revert "fix" This reverts commit 820ff88120d4fb4fc2bdcd8ee52229d1bfb83c17. * Revert "Revert "Merge branch 'master' of https://github.com/evnydd0sf/RSS-Hub"" This reverts commit ce67e0b53c231a8a8527b7407211aff1ab7e50d4. * 增加微信公众号解析引导。 * 修正url * 适配微信公众号内容。 * 适配站内文章、微信公号号文章和未知文章引导。 * Update wechat-mp.js * fix fetch wechat bug * 增加设计学院研创、后浪模块 * bugfix * Revert "Merge branch 'DIYgod:master' into master" This reverts commit 102cb48db6990fd5a699d2e46bf05d58be2e5ba5, reversing changes made to ccac4be5180ff7c2d81763efa7c09cf0b752ddc4. * Update university.md * Revert "Revert "Merge branch 'DIYgod:master' into master"" This reverts commit c8841910b83ec4a07e0d92d2d65feb192af9e5e3. * fix fetch listname * fix: switch default case Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- docs/university.md | 27 +++++++++--------- lib/utils/wechat-mp.js | 1 + lib/v2/nua/dc.js | 18 +++++++++--- lib/v2/nua/gra.js | 2 +- lib/v2/nua/index.js | 2 +- lib/v2/nua/sxw.js | 2 +- lib/v2/nua/utils.js | 62 ++++++++++++++++++++++++++++-------------- 7 files changed, 73 insertions(+), 41 deletions(-) diff --git a/docs/university.md b/docs/university.md index fedeb1cb4e..4f4dd2c8bf 100644 --- a/docs/university.md +++ b/docs/university.md @@ -2116,14 +2116,16 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS ### 设计学院 - + -| 新闻模块 | 参数 | -| ---------- | ------- | -| 学院新闻 NEWS | news | -| 教学 TEACH | teach | -| 项目 PROJECT | project | -| 党团 PARTY | party | +| 新闻模块 | 参数 | +| ---------------------- | ---------- | +| 学院新闻 NEWS | news | +| 展览 EXHIBITION | exhibition | +| 研创 RESEARCH & CREATION | rc | +| 项目 PROJECT | project | +| 党团 PARTY | party | +| 后浪 YOUTH | youth | @@ -2131,12 +2133,11 @@ jsjxy.hbut.edu.cn 证书链不全,自建 RSSHub 可设置环境变量 NODE_TLS -| 新闻模块 | 参数 | -| ----- | ---- | -| 招生工作 | 1959 | -| 培养工作 | 1962 | -| 学位工作 | 1958 | -| 思政与管理 | 1960 | +| 新闻模块 | 参数 | +| ---- | ---- | +| 招生工作 | 1959 | +| 培养工作 | 1962 | +| 学位工作 | 1958 | diff --git a/lib/utils/wechat-mp.js b/lib/utils/wechat-mp.js index 17d3cf48b2..52904dd7a1 100644 --- a/lib/utils/wechat-mp.js +++ b/lib/utils/wechat-mp.js @@ -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. * diff --git a/lib/v2/nua/dc.js b/lib/v2/nua/dc.js index a5e9d8af13..d7df910739 100644 --- a/lib/v2/nua/dc.js +++ b/lib/v2/nua/dc.js @@ -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], diff --git a/lib/v2/nua/gra.js b/lib/v2/nua/gra.js index 4a80156e8b..9d9daed64b 100644 --- a/lib/v2/nua/gra.js +++ b/lib/v2/nua/gra.js @@ -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], diff --git a/lib/v2/nua/index.js b/lib/v2/nua/index.js index a50b524816..57ae600b62 100644 --- a/lib/v2/nua/index.js +++ b/lib/v2/nua/index.js @@ -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], diff --git a/lib/v2/nua/sxw.js b/lib/v2/nua/sxw.js index dc2d454901..750912afbd 100644 --- a/lib/v2/nua/sxw.js +++ b/lib/v2/nua/sxw.js @@ -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], diff --git a/lib/v2/nua/utils.js b/lib/v2/nua/utils.js index ee3fb34b42..fedef79f56 100644 --- a/lib/v2/nua/utils.js +++ b/lib/v2/nua/utils.js @@ -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 `${text}`; +} 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, - }, - }); - const $ = cheerio.load(result.data); - - item.author = $('.arti_publisher').text() + ' ' + $('.arti_views').text(); - item.description = $(artiContent).html(); - - return item; + 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; + } }) ) );