Files
RSSHub/lib/v2/gov/gz/index.js
T
drgnchan 51ec49d0de feat(route): 新增广州市人民政府 (#11339)
* feat[route]: 新增广州市人民政府

* fix(v2ex): enable allowEmpty and enrich pubDate

* refactor: move `gzgov` dir under `gov`

* refactor: replace `gzgov` by `gz` and change doc accordingly

* refactor: polish code

* refactor: polish code

* fix: maintainer path
2022-12-08 01:15:00 +08:00

39 lines
1022 B
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const rootUrl = 'https://www.gz.gov.cn';
const urlMap = {
gzyw: 'gzyw',
jrtt: 'jrtt',
tzgg: 'tzgg',
zcjd: 'zcjd/zcjd',
};
module.exports = async (ctx) => {
const channel = ctx.params.channel;
const category = ctx.params.category;
const url = `${rootUrl}/${channel}/${urlMap[category]}/`;
const response = await got(url);
const $ = cheerio.load(response.data);
const items = $('.news_list li')
.toArray()
.map((item) => {
item = $(item);
const href = item.find('a').attr('href');
return {
title: item.find('a').attr('title'),
link: href,
pubDate: parseDate(item.find('span').text()),
};
});
ctx.state.data = {
title: `广州市人民政府 - ${$('.main_title').text()}`,
link: url,
item: items,
};
};