From 7d48b862d54a5ff8644419d055a3cddd827ddf47 Mon Sep 17 00:00:00 2001 From: cssxsh <32539286+cssxsh@users.noreply.github.com> Date: Tue, 22 Oct 2019 11:30:36 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=9B=BB=E6=92=83Online=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=B0=81=E9=9D=A2=E5=88=B0=20media:content=20(#3305)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/dengekionline/new.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/routes/dengekionline/new.js b/lib/routes/dengekionline/new.js index 06abf3c2f..5a7eaf072 100644 --- a/lib/routes/dengekionline/new.js +++ b/lib/routes/dengekionline/new.js @@ -64,21 +64,21 @@ module.exports = async (ctx) => { baseUrl: host, }); const data = response.data; - const link = response.link; + const link = response.url; // 过滤处理新闻列表数据 const $ = cheerio.load(data); - const list = $('ul.gNews_list').find('a'); + const list = $('a', 'ul.gNews_list'); const description = $('meta[name="description"]').attr('content'); // 整理信息 const item = await Promise.all( list .map(async (index, element) => { - const liArr = $(element).find('li'); - const date = $(element) - .find('time') - .attr('datetime'); + const liArr = $('li', element); + const date = $('time', element).attr('datetime'); const newLink = $(element).attr('href'); + // 新闻封面 + const cover = $('img', element); const category = liArr.map((index, li) => $(li).text()).get(); // 日本时区为东9区 const pubDate = new Date(`${date} GMT+0900`).toUTCString(); @@ -91,12 +91,8 @@ module.exports = async (ctx) => { }); const $ = cheerio.load(result.data); const title = $('.gEntry_title').text(); - const description = $('.gEntry_body') - .find('p') - .html(); - const author = $('.gEntry_athorList') - .find('dd') - .text(); + const description = $('p', '.gEntry_body').html(); + const author = $('dd', '.gEntry_athorList').text(); const info = { title: title, description: description, @@ -111,6 +107,13 @@ module.exports = async (ctx) => { link: newInfo.url, category: category, description: newInfo.description, + media: { + content: { + url: cover.attr('data-src'), + expression: 'full', + width: cover.attr('width'), + }, + }, author: newInfo.author, guid: newInfo.url, pubDate: pubDate,