Files
RSSHub/lib/v2/gov/mof/bond.js
T
la3rence fcbb3f402c feat(route): add mof (bond management) 中华人民共和国财政部-专题-政府债券管理 (#14094)
* feat(route): add mof (bond management)

* fix(router): re-order router config and add radar for mof

* feat(router): radar param in route doc

* fix(radar): add index source for mof

* feat(radar): more source path for mof

* Update website/docs/routes/government.mdx

---------
2023-12-21 22:46:05 +08:00

52 lines
1.7 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
const domain = 'gks.mof.gov.cn';
const theme = 'guozaiguanli';
module.exports = async (ctx) => {
const { category = 'gzfxgzdt' } = ctx.params;
const currentUrl = `https://${domain}/ztztz/${theme}/${category}/`;
const { data: response } = await got(currentUrl);
const $ = cheerio.load(response);
const title = $('title').text();
const author = $('div.zzName').text();
const siteName = $('meta[name="SiteName"]').prop('content');
const description = $('meta[name="ColumnDescription"]').prop('content');
const indexes = $('ul.liBox li')
.toArray()
.map((li) => {
const a = $(li).find('a');
const pubDate = $(li).find('span').text();
const href = a.prop('href');
const link = href.startsWith('http') ? href : new URL(href, currentUrl).href;
return {
title: a.prop('title'),
link,
pubDate: timezone(parseDate(pubDate), +8),
};
});
const items = await Promise.all(
indexes.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: detailResponse } = await got(item.link);
const content = cheerio.load(detailResponse);
item.description = content('div.my_doccontent').html();
item.author = author;
return item;
})
)
);
ctx.state.data = {
item: items,
title,
link: currentUrl,
description: `${description} - ${siteName}`,
author,
};
};