fix(route/tencent): Add cover image for video page and small video page (#18642)
* fix(route/zsxq): 优化问答型消息可读性 * fix(route/zsxq): unexpected any type * fix(route/zsxq): Handling of questions from anonymous users * fix(route/tencent): Add cover image for video page and small video page * fix(route/tencent): Avoid duplicating similar code * remove redundant attribute
This commit is contained in:
parent
d7f476ce16
commit
280279456a
|
|
@ -54,44 +54,47 @@ async function handler(ctx): Promise<Data> {
|
|||
const author = item.source;
|
||||
const abstract = item.abstract;
|
||||
|
||||
return item.articletype === '4'
|
||||
? {
|
||||
title,
|
||||
description: abstract,
|
||||
link: itemUrl,
|
||||
author,
|
||||
pubDate,
|
||||
}
|
||||
: cache.tryGet(itemUrl, async () => {
|
||||
const response = await got(itemUrl);
|
||||
const $ = load(response.data);
|
||||
const data = JSON.parse(
|
||||
$('script:contains("window.DATA")')
|
||||
.text()
|
||||
.match(/window\.DATA = ({.+});/)[1]
|
||||
);
|
||||
const $data = load(data.originContent?.text || '', null, false);
|
||||
if ($data) {
|
||||
// Not video page
|
||||
$data('*')
|
||||
.contents()
|
||||
.filter((_, elem) => elem.type === 'comment')
|
||||
.replaceWith((_, elem) =>
|
||||
art(path.join(__dirname, '../templates/news/image.art'), {
|
||||
attribute: elem.data.trim(),
|
||||
originAttribute: data.originAttribute,
|
||||
})
|
||||
);
|
||||
}
|
||||
if (item.articletype === '4' || item.articletype === '118') {
|
||||
// Video
|
||||
return {
|
||||
title,
|
||||
description: `<a href=${item.url}><img src="${item.articletype === '4' ? item.miniProShareImage : item.miniVideoPic}" style="width: 100%"></a>`,
|
||||
link: itemUrl,
|
||||
author,
|
||||
pubDate,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
title,
|
||||
description: $data.html() || abstract,
|
||||
link: itemUrl,
|
||||
author,
|
||||
pubDate,
|
||||
};
|
||||
});
|
||||
return cache.tryGet(itemUrl, async () => {
|
||||
const response = await got(itemUrl);
|
||||
const $ = load(response.data);
|
||||
const data = JSON.parse(
|
||||
$('script:contains("window.DATA")')
|
||||
.text()
|
||||
.match(/window\.DATA = ({.+});/)[1]
|
||||
);
|
||||
const $data = load(data.originContent?.text || '', null, false);
|
||||
if ($data) {
|
||||
// Not video page
|
||||
$data('*')
|
||||
.contents()
|
||||
.filter((_, elem) => elem.type === 'comment')
|
||||
.replaceWith((_, elem) =>
|
||||
art(path.join(__dirname, '../templates/news/image.art'), {
|
||||
attribute: elem.data.trim(),
|
||||
originAttribute: data.originAttribute,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
title,
|
||||
description: $data.html() || abstract,
|
||||
link: itemUrl,
|
||||
author,
|
||||
pubDate,
|
||||
};
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue