-
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.
- Loading branch information
Ethan Shen
authored
Nov 27, 2021
1 parent
713253b
commit d1c84c1
Showing
5 changed files
with
88 additions
and
7 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,54 @@ | ||
const got = require('@/utils/got'); | ||
const cheerio = require('cheerio'); | ||
const { parseDate } = require('@/utils/parse-date'); | ||
|
||
module.exports = async (ctx) => { | ||
const fid = ctx.params.id; | ||
const state = ctx.params.state ?? '1'; | ||
|
||
const rootUrl = 'http://liuyan.people.com.cn'; | ||
const currentUrl = `${rootUrl}/threads/list?fid=${fid}#state=${state}`; | ||
|
||
let currentForum; | ||
|
||
const apiResponse = await got({ | ||
method: 'post', | ||
url: `${rootUrl}/threads/queryThreadsList`, | ||
form: { | ||
fid, | ||
state, | ||
lastItem: 0, | ||
}, | ||
}); | ||
|
||
const list = apiResponse.data.responseData.map((item) => ({ | ||
title: item.subject, | ||
author: item.nickName, | ||
link: `${rootUrl}/threads/content?tid=${item.tid}`, | ||
pubDate: parseDate(item.threadsCheckTime * 1000), | ||
})); | ||
|
||
const items = await Promise.all( | ||
list.map((item) => | ||
ctx.cache.tryGet(item.link, async () => { | ||
const detailResponse = await got({ | ||
method: 'get', | ||
url: item.link, | ||
}); | ||
|
||
const content = cheerio.load(detailResponse.data); | ||
|
||
item.description = content('.content').html(); | ||
currentForum = currentForum ?? content('#currentForum').text(); | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
ctx.state.data = { | ||
title: `${currentForum} - 领导留言板 - 人民网`, | ||
link: currentUrl, | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
'/liuyan/:id/:state?': ['nczitzk'], | ||
}; |
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,13 @@ | ||
module.exports = { | ||
'people.com': { | ||
_name: '人民网', | ||
liuyan: [ | ||
{ | ||
title: '领导留言板', | ||
docs: 'https://docs.rsshub.app/traditional-media.html#ren-min-wang-ling-dao-liu-yan-ban', | ||
source: '/', | ||
target: '/people/liuyan/:id/:state?', | ||
}, | ||
], | ||
}, | ||
}; |
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,3 @@ | ||
module.exports = function (router) { | ||
router.get('/liuyan/:id/:state?', require('./liuyan')); | ||
}; |