-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 ---------
- Loading branch information
Showing
5 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters