From 64d87889decc60586df594dd6cb08eb04ea49fe2 Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Mon, 8 Jan 2024 12:22:35 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E4=B8=AD=E5=8D=8E?= =?UTF-8?q?=E5=85=A8=E5=9B=BD=E4=B8=93=E5=88=A9=E4=BB=A3=E7=90=86=E5=B8=88?= =?UTF-8?q?=E5=8D=8F=E4=BC=9A=20(#14197)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/v2/acpaa/index.js | 57 +++++++++++++++++++++++++++++++++++ lib/v2/acpaa/maintainer.js | 3 ++ lib/v2/acpaa/radar.js | 19 ++++++++++++ lib/v2/acpaa/router.js | 3 ++ website/docs/routes/other.mdx | 6 ++++ 5 files changed, 88 insertions(+) create mode 100644 lib/v2/acpaa/index.js create mode 100644 lib/v2/acpaa/maintainer.js create mode 100644 lib/v2/acpaa/radar.js create mode 100644 lib/v2/acpaa/router.js diff --git a/lib/v2/acpaa/index.js b/lib/v2/acpaa/index.js new file mode 100644 index 000000000..6a96add20 --- /dev/null +++ b/lib/v2/acpaa/index.js @@ -0,0 +1,57 @@ +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 { id = '1', name = '重要通知' } = ctx.params; + const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30; + + const rootUrl = 'http://www.acpaa.cn'; + const currentUrl = new URL(`article/taglist.jhtml?tagIds=${id}&tagname=${name}`, rootUrl).href; + + const { data: response } = await got(currentUrl); + + const $ = cheerio.load(response); + + let items = $('div.text01 ul li a[title]') + .slice(0, limit) + .toArray() + .map((item) => { + item = $(item); + + return { + title: item.prop('title'), + link: new URL(item.prop('href'), rootUrl).href, + pubDate: timezone(parseDate(item.find('span[title]').prop('title')), +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.title = content('div.xhjj_head01').text(); + item.description = content('div.text01').html(); + + return item; + }) + ) + ); + + const author = $('title').text().replace(/-/g, ''); + const subtitle = $('span.myTitle').text().trim(); + + ctx.state.data = { + item: items, + title: `${author} - ${subtitle}`, + link: currentUrl, + description: $('meta[property="og:description"]').prop('content'), + language: 'zh', + subtitle, + author, + }; +}; diff --git a/lib/v2/acpaa/maintainer.js b/lib/v2/acpaa/maintainer.js new file mode 100644 index 000000000..de07fba0f --- /dev/null +++ b/lib/v2/acpaa/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:id?/:name?': ['nczitzk'], +}; diff --git a/lib/v2/acpaa/radar.js b/lib/v2/acpaa/radar.js new file mode 100644 index 000000000..3be0bb419 --- /dev/null +++ b/lib/v2/acpaa/radar.js @@ -0,0 +1,19 @@ +module.exports = { + 'acpaa.cn': { + _name: '中华全国专利代理师协会', + '.': [ + { + title: '文章', + docs: 'https://docs.rsshub.app/routes/other#zhong-hua-quan-guo-zhuan-li-dai-li-shi-xie-hui', + source: ['/article/taglist.jhtml'], + target: (url) => { + url = new URL(url); + const id = url.searchParams.get('id'); + const name = url.searchParams.get('name'); + + return `/acpaa${id ? `/${id}${name ? `/${name}` : ''}` : ''}`; + }, + }, + ], + }, +}; diff --git a/lib/v2/acpaa/router.js b/lib/v2/acpaa/router.js new file mode 100644 index 000000000..b9338560b --- /dev/null +++ b/lib/v2/acpaa/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/:id?/:name?', require('./')); +}; diff --git a/website/docs/routes/other.mdx b/website/docs/routes/other.mdx index 42aeebd69..273321b10 100644 --- a/website/docs/routes/other.mdx +++ b/website/docs/routes/other.mdx @@ -1065,6 +1065,12 @@ Specify options (in the format of query string) in parameter `routeParams` param | short | zs | xh | xc | xhmr | xhmc | xcmr | xcmc | +## 中华全国专利代理师协会 {#zhong-hua-quan-guo-zhuan-li-dai-li-shi-xie-hui} + +### 标签 {#zhong-hua-quan-guo-zhuan-li-dai-li-shi-xie-hui-biao-qian} + + + ## はてな {#%E3%81%AF%E3%81%A6%E3%81%AA} ### はてな匿名ダイアリー - 人気記事アーカイブ {#%E3%81%AF%E3%81%A6%E3%81%AA-%E3%81%AF%E3%81%A6%E3%81%AA-ni-ming-%E3%83%80%E3%82%A4%E3%82%A2%E3%83%AA%E3%83%BC-ren-qi-ji-shi-%E3%82%A2%E3%83%BC%E3%82%AB%E3%82%A4%E3%83%96}