fix(route): coindesk consensus magazine (#12086)

* update Coindesk Consensus Magazine route

* Update lib/v2/coindesk/index.js

* Update lib/v2/coindesk/index.js

---------

Co-authored-by: pull[bot] <39814207+pull[bot]@users.noreply.github.com>
This commit is contained in:
James Shih 2023-03-13 17:16:56 +08:00 committed by GitHub
parent f4997c45ad
commit c4eb096cf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 7 deletions

View File

@ -5,9 +5,8 @@ const rootUrl = 'https://www.coindesk.com';
module.exports = async (ctx) => {
const channel = ctx.params.channel ?? 'consensus-magazine';
const response = await got.get(`${rootUrl}/${channel}`);
const response = await got.get(`${rootUrl}/${channel}/`);
const $ = cheerio.load(response.data);
const title = $('div.title-holder h2').text();
const content = JSON.parse(
$('#fusion-metadata')
.text()
@ -16,16 +15,15 @@ module.exports = async (ctx) => {
const o1 = content['websked-collections'];
// Object key names are different every week
const feature = o1[Object.keys(o1)[2]];
const opinion = o1[Object.keys(o1)[3]];
const articles = o1[Object.keys(o1)[2]];
const list = [...feature.data, ...opinion.data];
const list = articles.data;
const items = list.map((item) => ({
title: item.headlines.basic,
link: rootUrl + item.canonical_url,
description: title + '<br><br>' + item.subheadlines.basic,
pubDate: item.publish_date,
description: item.subheadlines.basic,
pubDate: item.display_date,
}));
ctx.state.data = {