feat: 优化即刻咨询台 (#5006)
This commit is contained in:
parent
320d68aaab
commit
963838dea3
|
|
@ -17,11 +17,8 @@ module.exports = async (ctx) => {
|
|||
const raw = $('[type = "application/json"]').html();
|
||||
const data = JSON.parse(raw).props.pageProps;
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${data.user.screenName}的即刻动态`,
|
||||
link: `https://m.okjike.com/users/${id}`,
|
||||
image: data.user.avatarImage.picUrl,
|
||||
item: data.posts.map((item) => {
|
||||
const items = await Promise.all(
|
||||
data.posts.map(async (item) => {
|
||||
const typeMap = {
|
||||
ORIGINAL_POST: '发布',
|
||||
REPOST: '转发',
|
||||
|
|
@ -33,6 +30,7 @@ module.exports = async (ctx) => {
|
|||
const linkMap = {
|
||||
ORIGINAL_POST: `https://m.okjike.com/originalPosts/${item.id}`,
|
||||
REPOST: `https://m.okjike.com/reposts/${item.id}`,
|
||||
MEDIUM: `https://www.okjike.com/medium/${item.id}`,
|
||||
// OFFICIAL_MESSAGE: `https://m.okjike.com/originalPosts/${item.id}`,
|
||||
// ANSWER: `https://m.okjike.com/answer/${item.id}`,
|
||||
// QUESTION: `https://m.okjike.com/originalPosts/${item.id}`,
|
||||
|
|
@ -72,41 +70,76 @@ module.exports = async (ctx) => {
|
|||
}
|
||||
// 部分功能未知
|
||||
/* else if (item.type === 'ANSWER') {
|
||||
let answerTextTemplate = '';
|
||||
let answerImgTemplate = '';
|
||||
let answerImgKeys = [];
|
||||
item.richtextContent.blocks &&
|
||||
item.richtextContent.blocks.forEach((item) => {
|
||||
if (item.entityRanges.length && item.text === '[图片]') {
|
||||
answerImgKeys = [...answerImgKeys, ...Object.keys(item.entityRanges)];
|
||||
} else {
|
||||
answerTextTemplate += item.text;
|
||||
}
|
||||
});
|
||||
let answerTextTemplate = '';
|
||||
let answerImgTemplate = '';
|
||||
let answerImgKeys = [];
|
||||
item.richtextContent.blocks &&
|
||||
item.richtextContent.blocks.forEach((item) => {
|
||||
if (item.entityRanges.length && item.text === '[图片]') {
|
||||
answerImgKeys = [...answerImgKeys, ...Object.keys(item.entityRanges)];
|
||||
} else {
|
||||
answerTextTemplate += item.text;
|
||||
}
|
||||
});
|
||||
|
||||
if (answerImgKeys.length) {
|
||||
answerImgKeys.forEach((key) => {
|
||||
const entity = item.richtextContent.entityMap[key];
|
||||
if (entity.type.toUpperCase() === 'IMAGE') {
|
||||
answerImgTemplate += `<br><img referrerpolicy="no-referrer" src="${entity.data.pictureUrl.middlePicUrl}">`;
|
||||
}
|
||||
});
|
||||
}
|
||||
const answerContent = `回答: ${answerTextTemplate}${answerImgTemplate}`;
|
||||
content = `${content}${answerContent}`.replace(/\n|\r/g, '<br>');
|
||||
} else if (item.type === 'QUESTION') {
|
||||
content = `在主题 <a href="https://web.okjike.com/topic/${item.topic.id}/official" target="_blank">${item.topic.content}</a> 提出了一个问题:<br><br>${content}`;
|
||||
} else if (item.type === 'PERSONAL_UPDATE') {
|
||||
shortenTitle = item.topic.content;
|
||||
content = `<img referrerpolicy="no-referrer" src="${item.topic.squarePicture.picUrl}"> 主题简介:<br>${item.topic.briefIntro.replace(/(?:\r\n|\r|\n)/g, '<br>')}`;
|
||||
}*/
|
||||
if (answerImgKeys.length) {
|
||||
answerImgKeys.forEach((key) => {
|
||||
const entity = item.richtextContent.entityMap[key];
|
||||
if (entity.type.toUpperCase() === 'IMAGE') {
|
||||
answerImgTemplate += `<br><img referrerpolicy="no-referrer" src="${entity.data.pictureUrl.middlePicUrl}">`;
|
||||
}
|
||||
});
|
||||
}
|
||||
const answerContent = `回答: ${answerTextTemplate}${answerImgTemplate}`;
|
||||
content = `${content}${answerContent}`.replace(/\n|\r/g, '<br>');
|
||||
} else if (item.type === 'QUESTION') {
|
||||
content = `在主题 <a href="https://web.okjike.com/topic/${item.topic.id}/official" target="_blank">${item.topic.content}</a> 提出了一个问题:<br><br>${content}`;
|
||||
} else if (item.type === 'PERSONAL_UPDATE') {
|
||||
shortenTitle = item.topic.content;
|
||||
content = `<img referrerpolicy="no-referrer" src="${item.topic.squarePicture.picUrl}"> 主题简介:<br>${item.topic.briefIntro.replace(/(?:\r\n|\r|\n)/g, '<br>')}`;
|
||||
}*/
|
||||
|
||||
return {
|
||||
const single = {
|
||||
title: `${typeMap[item.type]}了: ${shortenTitle}`,
|
||||
description: `${content}${linkTemplate}${imgTemplate}`,
|
||||
pubDate: new Date(item.createdAt).toUTCString(),
|
||||
link: `${linkMap[item.type]}`,
|
||||
};
|
||||
}),
|
||||
|
||||
if (id === 'wenhao1996' && item.topic.id === '553870e8e4b0cafb0a1bef68') {
|
||||
single.link = item.urlsInText[0].url;
|
||||
|
||||
const data = (
|
||||
await got({
|
||||
method: 'get',
|
||||
url: single.link,
|
||||
headers: {
|
||||
Referer: `https://m.okjike.com/users/${id}`,
|
||||
},
|
||||
})
|
||||
).data;
|
||||
const $$ = cheerio.load(data);
|
||||
$$('span.num,span.arrow').remove();
|
||||
|
||||
single.title = `一觉醒来世界发生了什么 ${$$('title').text()}`;
|
||||
|
||||
single.description = '';
|
||||
$$('div.container')
|
||||
.find('li.item')
|
||||
// eslint-disable-next-line array-callback-return
|
||||
.map((i, j) => {
|
||||
single.description += `<a href="${$$(j).find('a').attr('href')}">${$$(j).find('a').text()}</a><br/>`;
|
||||
});
|
||||
}
|
||||
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${data.user.screenName}的即刻动态`,
|
||||
link: `https://m.okjike.com/users/${id}`,
|
||||
image: data.user.avatarImage.picUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue