mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-24 12:15:32 +08:00
feat: add u.s. department of the treasury press releases (#6393)
Co-authored-by: Henry Wang <hi@henry.wang>
This commit is contained in:
@@ -3676,6 +3676,9 @@ router.get('/cool18/:id?/:type?/:keyword?', require('./routes/cool18/index'));
|
||||
// 美国贸易代表办公室
|
||||
router.get('/ustr/press-releases/:year?/:month?', require('./routes/us/ustr/press-releases'));
|
||||
|
||||
// 美国财政部
|
||||
router.get('/treasury/press-releases/:category?/:title?', require('./routes/us/treasury/press-releases'));
|
||||
|
||||
// Bandisoft
|
||||
router.get('/bandisoft/:id?/:lang?', require('./routes/bandisoft/index'));
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const title = ctx.params.title || '';
|
||||
const category = ctx.params.category || 'all';
|
||||
|
||||
const rootUrl = 'https://home.treasury.gov';
|
||||
const currentUrl = `${rootUrl}/news/press-releases${category === 'all' ? '' : `/${category}`}${title === '' ? '' : `?title=${title}`}`;
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: currentUrl,
|
||||
});
|
||||
|
||||
const $ = cheerio.load(response.data);
|
||||
|
||||
const list = $('.featured-stories__headline a')
|
||||
.slice(0, 10)
|
||||
.map((_, item) => {
|
||||
item = $(item);
|
||||
return {
|
||||
title: item.text(),
|
||||
link: `${rootUrl}${item.attr('href')}`,
|
||||
};
|
||||
})
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map(
|
||||
async (item) =>
|
||||
await ctx.cache.tryGet(item.link, async () => {
|
||||
const detailResponse = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
});
|
||||
const content = cheerio.load(detailResponse.data);
|
||||
|
||||
item.description = content('.field--name-field-news-body').html();
|
||||
item.pubDate = new Date(content('time').attr('datetime')).toUTCString();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user