fix(route): tencent author (#14241)

This commit is contained in:
Tony 2024-01-14 18:11:00 +00:00 committed by GitHub
parent 7a94c42e94
commit a1c0e75542
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 4 deletions

View File

@ -1,8 +1,9 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');
const config = require('@/config').value;
const { art } = require('@/utils/render');
const { join } = require('path');
module.exports = async (ctx) => {
const mid = ctx.params.mid;
@ -18,7 +19,7 @@ module.exports = async (ctx) => {
const items = await Promise.all(
news.map((item) => {
const title = item.title;
const pubDate = timezone(parseDate(item.time), +8);
const pubDate = parseDate(item.timestamp, 'X');
const itemUrl = item.url;
const author = item.source;
const abstract = item.abstract;
@ -26,11 +27,26 @@ module.exports = async (ctx) => {
return ctx.cache.tryGet(itemUrl, async () => {
const response = await got(itemUrl);
const $ = cheerio.load(response.data);
const article = $('#ArticleContent');
const data = JSON.parse(
$('script:contains("window.DATA")')
.text()
.match(/window\.DATA = (\{.+\});/)[1]
);
const $data = cheerio.load(data.originContent.text, null, false);
$data('*')
.contents()
.filter((_, elem) => elem.type === 'comment')
.replaceWith((_, elem) =>
art(join(__dirname, '../templates/news/image.art'), {
attribute: elem.data.trim(),
originAttribute: data.originAttribute,
})
);
return {
title,
description: article.html() || abstract,
description: $data.html() || abstract,
link: itemUrl,
author,
pubDate,

View File

@ -0,0 +1,4 @@
{{ if attribute?.startsWith('IMG') && originAttribute[attribute] }}
{{ set image = originAttribute[attribute] }}
<img src="{{ image.bigOrigUrl }}" style="{{ image.style }}" >
{{ /if }}