mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-02 01:58:11 +08:00
refactor(route/jike): extract repeated logic; fix await (#9698)
* refactor(route/jike): rename `common` -> `utils` Signed-off-by: Rongrong <i@rong.moe> * refactor(route/jike): extract repeated logic Signed-off-by: Rongrong <i@rong.moe> * fix(route/jike): lack await Signed-off-by: Rongrong <i@rong.moe>
This commit is contained in:
@@ -1,36 +1,21 @@
|
||||
const got = require('@/utils/got');
|
||||
const dayjs = require('dayjs');
|
||||
const common = require('./common');
|
||||
const cheerio = require('cheerio');
|
||||
const { constructTopicEntry } = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
const topicUrl = `https://m.okjike.com/topics/${id}`;
|
||||
|
||||
const response = await got(`https://m.okjike.com/topics/${id}`);
|
||||
const data = await constructTopicEntry(ctx, topicUrl);
|
||||
|
||||
const html = response.data;
|
||||
const $ = cheerio.load(html);
|
||||
const raw = $('[type = "application/json"]').html();
|
||||
const data = JSON.parse(raw).props.pageProps;
|
||||
|
||||
if (common.emptyResponseCheck(ctx, data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const title = data.topic.content;
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${title} - 即刻`,
|
||||
link: `https://m.okjike.com/topics/${id}`,
|
||||
description: `${title} - 即刻`,
|
||||
item: data.posts.map((item) => {
|
||||
if (data) {
|
||||
ctx.state.data.item = data.posts.map((item) => {
|
||||
const date = dayjs(item.createdAt);
|
||||
return {
|
||||
title: `${title} ${date.format('MM月DD日')}`,
|
||||
title: `${data.topic.content} ${date.format('MM月DD日')}`,
|
||||
description: item.content.replace(/\n/g, '<br>'),
|
||||
pubDate: date.toDate(),
|
||||
link: `https://m.okjike.com/originalPosts/${item.id}`,
|
||||
};
|
||||
}),
|
||||
};
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user