* 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
20 lines
672 B
JavaScript
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,
|
|
};
|
|
};
|