From b523c4dc3186c1a9c2a45533aba6aaf470cc0ec1 Mon Sep 17 00:00:00 2001 From: Felix Hsu Date: Fri, 30 Sep 2022 00:14:20 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20bphc=20=E5=8C=97=E4=BA=AC?= =?UTF-8?q?=E5=85=B1=E6=9C=89=E4=BA=A7=E6=9D=83=E4=BD=8F=E6=88=BF=E7=A7=9F?= =?UTF-8?q?=E8=B5=81=E5=B9=B3=E5=8F=B0=20(#10955)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * bphc * radar ok * change maintainer * fix null checking err * rss link should be rootUrl * fix: sort routes --- docs/government.md | 12 +++++++ lib/v2/gov/beijing/bphc/index.js | 54 ++++++++++++++++++++++++++++++++ lib/v2/gov/maintainer.js | 1 + lib/v2/gov/radar.js | 11 +++++++ lib/v2/gov/router.js | 1 + 5 files changed, 79 insertions(+) create mode 100644 lib/v2/gov/beijing/bphc/index.js diff --git a/docs/government.md b/docs/government.md index 182ed343d..81d7f5ef4 100644 --- a/docs/government.md +++ b/docs/government.md @@ -44,6 +44,18 @@ pageClass: routes +## 北京市保障房中心有限公司 + +### 北京市共有产权住房租赁服务平台 + + + +| 通知公告 | 项目介绍 | +| :----------: | :-----: | +| announcement | project | + + + ## 北京市教育委员会 ### 通知公告 diff --git a/lib/v2/gov/beijing/bphc/index.js b/lib/v2/gov/beijing/bphc/index.js new file mode 100644 index 000000000..f8d033e49 --- /dev/null +++ b/lib/v2/gov/beijing/bphc/index.js @@ -0,0 +1,54 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); +const timezone = require('@/utils/timezone'); + +const mapping = { + '/project': { + title: '项目介绍', + list: '/front/index/project/page', + detail: '/front/index/project', + link: '/#/communityDetail?id=', + }, + '/announcement': { + title: '通知公告', + list: '/front/announcement/page', + detail: '/front/announcement/', + link: '/#/announcementList/detail?id=', + }, +}; + +module.exports = async (ctx) => { + const rootUrl = 'http://gycp.bphc.com.cn:21000'; + const defaultPath = 'announcement'; + + const pathname = ctx.path.replace(/(^\/beijing\/bphc|\/$)/g, ''); + const key = pathname === '' ? defaultPath : pathname.endsWith('/') ? pathname.slice(0, -1) : pathname; + const obj = mapping[key]; + const currentUrl = `${rootUrl}${obj.list}`; + + const listResp = await got(currentUrl).json(); + const list = listResp.data?.records ?? []; + const items = await Promise.all( + list.map((item) => { + const detail = `${rootUrl}${obj.detail}/${item.id}`; + return ctx.cache.tryGet(detail, async () => { + const detailResponse = await got(detail).json(); + const description = (detailResponse.data?.content || detailResponse.data?.introduction) ?? ''; + const single = { + title: item.title || item.fullName, + author: description.match(/来源:(.*?) `/gov/bphc/${new URL(url).href.match(/gycpt\.bphc\.com\.cn\/(.*)/)[1]}`, + }, + ], + }, 'ccdi.gov.cn': { _name: '中央纪委国家监委', www: [ diff --git a/lib/v2/gov/router.js b/lib/v2/gov/router.js index 466b2eae7..fdf19f16c 100644 --- a/lib/v2/gov/router.js +++ b/lib/v2/gov/router.js @@ -29,6 +29,7 @@ module.exports = function (router) { router.get(/stats(\/[\w/-]+)?/, require('./stats')); // province router.get(/anhui\/kjt\/([\w\d/-]+)?/, require('./anhui/kjt')); + router.get(/beijing\/bphc(\/[\w/-]+)?/, require('./beijing/bphc')); router.get('/beijing/jw/tzgg', require('./beijing/jw/tzgg')); router.get('/beijing/kw/:channel', require('./beijing/kw/index')); router.get('/guangdong/tqyb/tfxtq', require('./guangdong/tqyb/tfxtq'));