Skip to content

Commit

Permalink
fix(route): coindesk consensus magazine (DIYgod#12086)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
jameshih and pull[bot] authored Mar 13, 2023
1 parent f4997c4 commit c4eb096
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/v2/coindesk/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 = {
Expand Down

0 comments on commit c4eb096

Please sign in to comment.