Files
RSSHub/lib/v2/gov/stats/index.js
T
Felix Hsu 0f2dd302c5 feat(route): Add stats.gov 国家统计局 (#10860)
* add new statsgov

* Fix radar.js

* 1. Fix the missing optional chaining operator in reg matching 2. add the missing timezone change

* remove the dup $ in item

* optimize url

* stats.gov.cn refactored

* Modify doc

* more flexible pathname parsing

* Fix radar data
2022-09-23 20:50:40 +08:00

20 lines
672 B
JavaScript

const { parseContList, parseXilan } = require('./utils');
module.exports = async (ctx) => {
const rootUrl = 'http://www.stats.gov.cn';
const defaultPath = '/tjsj/zxfb/';
let pathname = ctx.path.replace(/(^\/stats|\/$)/g, '');
pathname = pathname === '' ? defaultPath : pathname.endsWith('/') ? pathname : pathname + '/';
const currentUrl = `${rootUrl}${pathname}`;
const { list, title } = await parseContList(currentUrl, 'ul.center_list_contlist li a:not([id])', ctx);
const items = await Promise.all(list.map((item) => parseXilan(item, ctx)));
ctx.state.data = {
title,
link: currentUrl,
item: items,
};
};