fix: remove medium links and rss feeds

This commit is contained in:
Mrugesh Mohapatra
2019-06-15 23:45:30 +05:30
committed by mrugesh
parent 1d4ae06541
commit 0ffca02ec1
6 changed files with 7 additions and 51 deletions

View File

@ -2,7 +2,6 @@ import _ from 'lodash';
import compareDesc from 'date-fns/compare_desc';
import debug from 'debug';
import { getMediumFeed } from './medium';
import { getLybsynFeed } from './lybsyn';
const log = debug('fcc:rss:news-feed');
@ -13,7 +12,6 @@ class NewsFeed {
constructor() {
this.state = {
readyState: false,
mediumFeed: [],
lybsynFeed: [],
combinedFeed: []
};
@ -31,18 +29,17 @@ class NewsFeed {
refreshFeeds = () => {
const currentFeed = this.state.combinedFeed.slice(0);
log('grabbing feeds');
return Promise.all([getMediumFeed(), getLybsynFeed()])
.then(([mediumFeed, lybsynFeed]) =>
return Promise.all([getLybsynFeed()])
.then(([lybsynFeed]) =>
this.setState(state => ({
...state,
mediumFeed,
lybsynFeed
}))
)
.then(() => {
log('crossing the streams');
const { mediumFeed, lybsynFeed } = this.state;
const combinedFeed = [...mediumFeed, ...lybsynFeed].sort((a, b) => {
const { lybsynFeed } = this.state;
const combinedFeed = [...lybsynFeed].sort((a, b) => {
return compareDesc(a.isoDate, b.isoDate);
});
this.setState(state => ({

View File

@ -1,36 +0,0 @@
import Parser from 'rss-parser';
import _ from 'lodash';
const parser = new Parser();
const mediumFeed = 'https://medium.freecodecamp.org/feed';
function getExtract(str) {
return str.slice(0, str.indexOf('</p>') + 4);
}
function addResponsiveClass(str) {
return str.replace(/<img/g, '<img class="img-responsive"');
}
export function getMediumFeed() {
return new Promise((resolve, reject) => {
parser.parseURL(mediumFeed, (err, feed) => {
if (err) {
reject(err);
}
const items = feed.items
.map(item =>
_.pick(item, ['title', 'link', 'isoDate', 'content:encoded'])
)
.map(item => ({
...item,
extract: getExtract(item['content:encoded'])
}))
.map(item => _.omit(item, ['content:encoded']))
.map(item => ({ ...item, extract: addResponsiveClass(item.extract) }));
resolve(items);
});
});
}