diff --git a/docs/traditional-media.md b/docs/traditional-media.md
index 5e5871de10..77b2b439cc 100644
--- a/docs/traditional-media.md
+++ b/docs/traditional-media.md
@@ -178,15 +178,15 @@ Category 列表:
+
`;
- $('div.captions > p').each((i, e) => {
- $(images[i]).insertBefore(e);
- });
+ let hasBold = false;
- content = $('div.captions');
- } else {
- content = $('div.dia-lead-one');
- }
+ data.blocks.forEach((b) => {
+ switch (b.blockType) {
+ case 'summary':
+ description += `
${b.summary.join('`; + break; + case 'text': + b.htmlTokens.forEach((t) => { + t.forEach((tt) => { + switch (tt.type) { + case 'text': + if (hasBold) { + hasBold = false; + description += `${tt.content}`; + } else { + description += `
')}
${tt.content}
`; + } + break; + case 'boldText': + description = description.slice(0, -4); + description += `${tt.content}`; + hasBold = true; + break; - ProcessQuote($, content); - ProcessImage($, content); - Clean($, content); - - return content.html(); -}; - -const ProcessRank = ($, type) => { - let content, author; - - const pubDate = new Date($('div.time').text()); - pubDate.setHours(pubDate.getHours() - 8); - - content = $('div.dia-lead-one'); - if (type === 'news') { - if (content.length === 0) { - content = $('div.container'); - - author = $('div.author').text(); - } else { - author = $('div.nw').text(); - } - - ProcessQuote($, content); - ProcessImage($, content); - Clean($, content); - } else { - let images = $('div#slider_component_4_0 > img'); - if ($('div#slider_component_4_0 > img').length > 0) { - $('div.captions > p').each((i, e) => { - $(images[i]).insertBefore(e); - }); - content = $('div.captions'); - } else { - images = $('div#component_4_0 .sd-page > img'); - - content = cheerio.load(''); - content = content('div'); - - $('.sqbtnbox > .tzbox') - .slice(1) - .each((i, e) => { - $(images[i]).appendTo(content); - $(e).appendTo(content); + default: + break; + } + }); }); - } - } + break; + case 'image': + description += genFigure(b.image); + break; + case 'gallery': + b.images.forEach((t) => { + description += genFigure(t); + }); + break; + + default: + break; + } + }); return { - description: content.html(), - author, - pubDate, + title: data.title, + link: data.publishUrl, + author: data.authors[0].publishName, + description, + pubDate: new Date(data.publishTime).toUTCString(), }; }; -const ProcessQuote = ($, content) => { - content.find('div.ed-top').each((i, e) => { - const quote = $(e).siblings('p'); - if (quote.length > 0) { - $(`${quote.text()}`).insertBefore(e); - - $(quote).remove(); - $(e).remove(); - } - }); -}; - -const ProcessImage = ($, content) => { - content.find('a[href="javascript:;"]').each((i, e) => { - const img = $(e).find('img'); - $(img).insertBefore(e); - $(e).remove(); - }); -}; - -const Clean = ($, content) => { - content.find('div.clear, div.badoo, div.hu-bqsm, div.sign, div.xyy, div#component_14_0').each((i, e) => { - $(e).remove(); - }); -}; - module.exports = { ProcessFeed, - ProcessRank, }; diff --git a/lib/routes/dwnews/yaowen.js b/lib/routes/dwnews/yaowen.js index c78b32d8c3..2f6090d477 100644 --- a/lib/routes/dwnews/yaowen.js +++ b/lib/routes/dwnews/yaowen.js @@ -1,8 +1,9 @@ const got = require('@/utils/got'); -const cheerio = require('cheerio'); +const utils = require('./utils'); module.exports = async (ctx) => { let link = 'https://www.dwnews.com'; + const api = 'https://prod-site-api.dwnews.com/v2/articles'; let region, regionid, host, @@ -27,6 +28,10 @@ module.exports = async (ctx) => { title = `台湾${title}`; regionid = '10000119'; break; + case 'jingji': + title = `经济${title}`; + regionid = '10000123'; + break; default: break; } @@ -40,27 +45,17 @@ module.exports = async (ctx) => { const out = await Promise.all( list.data.items.map(async (item) => { - const cache = await ctx.cache.get(item.data.publishUrl); + const url = `${api}/${item.id}`; + const cache = await ctx.cache.get(url); if (cache) { return Promise.resolve(JSON.parse(cache)); } - const response = await got.get(encodeURI(item.data.publishUrl)); - const $ = cheerio.load(response.data); + const response = await got.get(url); - const pubDate = new Date(item.data.publishTime * 1000); - pubDate.setHours(pubDate.getHours() - 8); + const single = utils.ProcessFeed(response.data); - const description = $('article').html() || item.data.description; - - const single = { - title: item.data.title, - link: item.data.publishUrl, - author: item.data.authors[0].publishName, - description, - pubDate: pubDate.toUTCString(), - }; - ctx.cache.set(item.data.publishUrl, JSON.stringify(single)); + ctx.cache.set(url, JSON.stringify(single)); return Promise.resolve(single); }) ); @@ -68,7 +63,7 @@ module.exports = async (ctx) => { ctx.state.data = { title: `多维新闻网 - ${title}`, description: '多维新闻网—记住世界的轨迹 更需多维的视线,海外华人首选的中文门户新闻网站,及时全面的向全球海外华人更新世界各地时事政治、经济、科技、人文历史、图片、视频等新闻内容,是海外华人必上的新闻门户网站。', - link: link, + link, item: out, }; };