diff --git a/lib/v2/tencent/news/author.js b/lib/v2/tencent/news/author.js index 6921419346e3b3..d5fb5bb1605665 100644 --- a/lib/v2/tencent/news/author.js +++ b/lib/v2/tencent/news/author.js @@ -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, diff --git a/lib/v2/tencent/templates/news/image.art b/lib/v2/tencent/templates/news/image.art new file mode 100644 index 00000000000000..04120bbbfe2694 --- /dev/null +++ b/lib/v2/tencent/templates/news/image.art @@ -0,0 +1,4 @@ +{{ if attribute?.startsWith('IMG') && originAttribute[attribute] }} + {{ set image = originAttribute[attribute] }} + +{{ /if }}