diff --git a/docs/government.md b/docs/government.md index ad419b470..87c1e4478 100644 --- a/docs/government.md +++ b/docs/government.md @@ -1112,6 +1112,22 @@ pageClass: routes +## 中国军网 + +### 军队人才网 + + + +::: tip 提示 + +若订阅 [文职人员 - 工作动态](https://81rc.81.cn/wzry/gzdt),网址为 。截取 `https://81rc.81.cn` 到末尾的部分 `/wzry/gzdt` 作为参数,此时路由为 [`/81/81rc/wzry/gzdt`](https://rsshub.app/81/81rc/wzry/gzdt)。 + +若订阅子分类 [文职人员 - 各部门各单位招考动态](https://81rc.81.cn/wzry/jwjgbmhddwzkdt),网址为 。截取 `https://81rc.81.cn` 到末尾的部分 `/wzry/jwjgbmhddwzkdt` 作为参数,此时路由为 [`/81/81rc/wzry/jwjgbmhddwzkdt`](https://rsshub.app/81/81rc/wzry/jwjgbmhddwzkdt)。 + +::: + + + ## 中国科学技术协会 ### 通用 diff --git a/lib/v2/81/81rc/index.js b/lib/v2/81/81rc/index.js new file mode 100644 index 000000000..1be609e10 --- /dev/null +++ b/lib/v2/81/81rc/index.js @@ -0,0 +1,62 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const timezone = require('@/utils/timezone'); +const { parseDate } = require('@/utils/parse-date'); + +module.exports = async (ctx) => { + const thePath = ctx.path.replace(/^\/81rc/, ''); + const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30; + + const rootUrl = 'https://81rc.81.cn'; + + // The default is http://81rc.81.cn/sy/gzdt_210283. + const currentUrl = new URL(thePath || '/sy/gzdt_210283', rootUrl).href; + + const { data: response } = await got(currentUrl); + + const $ = cheerio.load(response); + + let items = $('div.left-news ul li a') + .slice(0, limit) + .toArray() + .map((item) => { + item = $(item); + + return { + title: item.text(), + link: new URL(item.prop('href'), rootUrl).href, + pubDate: timezone(parseDate(item.parent().find('span').text()), +8), + }; + }); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: detailResponse } = await got(item.link); + + const content = cheerio.load(detailResponse); + + item.description = content('.txt').html(); + item.author = content('meta[name="reporter"]').prop('content') || content('meta[name="author"]').prop('content'); + + return item; + }) + ) + ); + + const icon = $('link[rel="icon"]').prop('href'); + + ctx.state.data = { + item: items, + title: `军队人才网 - ${$('div.left-word') + .find('a') + .toArray() + .map((a) => $(a).text()) + .filter((a) => a !== '首页') + .join(' - ')}`, + link: currentUrl, + language: 'zh-cn', + icon, + logo: icon, + }; +}; diff --git a/lib/v2/81/maintainer.js b/lib/v2/81/maintainer.js new file mode 100644 index 000000000..0f9f036fa --- /dev/null +++ b/lib/v2/81/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/81rc/:path+': ['nczitzk'], +}; diff --git a/lib/v2/81/radar.js b/lib/v2/81/radar.js new file mode 100644 index 000000000..6337c63c5 --- /dev/null +++ b/lib/v2/81/radar.js @@ -0,0 +1,18 @@ +module.exports = { + '81.cn': { + _name: '中国军网', + '81rc': [ + { + title: '军队人才网', + docs: 'https://docs.rsshub.app/government.html#zhon-guo-jun-wang-jun-dui-ren-cai-wang', + source: ['/'], + target: (params, url) => { + url = new URL(url); + const path = url.href.match(/81rc\.81\.cn(.*?)/).replace(/\/index\.html$/, ''); + + return `/81/81rc${path === '/' ? '' : path}`; + }, + }, + ], + }, +}; diff --git a/lib/v2/81/router.js b/lib/v2/81/router.js new file mode 100644 index 000000000..b3c2454f5 --- /dev/null +++ b/lib/v2/81/router.js @@ -0,0 +1,3 @@ +module.exports = function (router) { + router.get(/81rc(\/[\w-/]+)?/, require('./81rc')); +};