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 政策研究, 工作论文 and refactor to V2 (#9324)
* feat(route): add 政策研究, 工作论文 and refactor to V2 * fix: depreciated url.resolve pubDate
- Loading branch information
Fatpandac
committed
Mar 15, 2022
1 parent
b93f6fe
commit 0ec2b01
Showing
10 changed files
with
133 additions
and
14 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const { processItems } = require('./utils'); | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
|
||
const host = 'http://www.pbc.gov.cn'; | ||
|
||
module.exports = async (ctx) => { | ||
const url = `${host}/redianzhuanti/118742/4122386/4122692/index.html`; | ||
|
||
const response = await got.post(url); | ||
const $ = cheerio.load(response.data); | ||
const list = $('li.clearfix') | ||
.map((_index, item) => ({ | ||
title: $(item).find('a').text(), | ||
link: new URL($(item).find('a').attr('href'), host).href, | ||
author: $(item).find('span.fr').text().replace(/…/g, ''), | ||
})) | ||
.get(); | ||
|
||
const items = await processItems(list, ctx); | ||
|
||
ctx.state.data = { | ||
title: '中国人民银行 工作论文', | ||
link: url, | ||
item: items, | ||
}; | ||
}; |
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,20 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
|
||
const processItems = async (list, ctx) => | ||
await Promise.all( | ||
list.map((item) => | ||
ctx.cache.tryGet(item.link, async () => { | ||
const detailResponse = await got.post(item.link); | ||
const content = cheerio.load(detailResponse.data); | ||
|
||
item.description = content('div.xxy_text').html(); | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
module.exports = { | ||
processItems, | ||
}; |
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,29 @@ | ||
const { processItems } = require('./utils'); | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
const timezone = require('@/utils/timezone'); | ||
|
||
const host = 'http://www.pbc.gov.cn'; | ||
|
||
module.exports = async (ctx) => { | ||
const url = `${host}/redianzhuanti/118742/4122386/4122510/index.html`; | ||
|
||
const response = await got.post(url); | ||
const $ = cheerio.load(response.data); | ||
const list = $('li.clearfix') | ||
.map((_index, item) => ({ | ||
title: $(item).find('a').text(), | ||
link: new URL($(item).find('a').attr('href'), host).href, | ||
pubDate: timezone(parseDate($(item).find('span.fr').text(), 'YYYY-MM-DD'), +8), | ||
})) | ||
.get(); | ||
|
||
const items = await processItems(list, ctx); | ||
|
||
ctx.state.data = { | ||
title: '中国人民银行 政策研究', | ||
link: url, | ||
item: items, | ||
}; | ||
}; |
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