diff --git a/src/data/sources/api.js b/src/data/sources/api.js index 854b647..bb2a303 100644 --- a/src/data/sources/api.js +++ b/src/data/sources/api.js @@ -33,13 +33,14 @@ class API { }; } - constructor(uri, type, apiKey) { + constructor(uri, type, baseHost, apiKey) { const axiosConfig = API.createAxiosConfig(uri, apiKey); + const host = baseHost || hostName(uri); this.fetch = API.fetch(axiosConfig); this.name = toHumanName(type); - this.host = hostName(uri); + this.host = host; this.type = type; - this.faviconURL = findFavicon(uri); + this.faviconURL = findFavicon(host); } } diff --git a/src/data/sources/sidebar.js b/src/data/sources/sidebar.js index e0052bc..993393e 100644 --- a/src/data/sources/sidebar.js +++ b/src/data/sources/sidebar.js @@ -1,10 +1,24 @@ const API = require('./api'); const types = require('../types'); +const queryString = require('query-string'); +const { valueSeq } = require('../../utils'); class Sidebar extends API { constructor() { const baseURL = 'https://sidebar.io/'; super(baseURL, types.Sidebar); + this.normalize = this.normalize.bind(this); + } + + normalize(data) { + return data.map(({ headline, url, date }) => ( + { + title: headline, + publishedAt: date, + link: valueSeq(queryString.parse(url))[0], + type: this.type, + } + )); } getListing() { @@ -12,7 +26,9 @@ class Sidebar extends API { } get listing() { - return this.getListing(); + return this.getListing() + .then(this.normalize) + .catch(e => { throw new Error(e) }); } }