diff --git a/lib/blog-feed-loader.js b/lib/blog-feed-loader.js index 286a6021e..4dd0b93b5 100644 --- a/lib/blog-feed-loader.js +++ b/lib/blog-feed-loader.js @@ -1,65 +1,2 @@ -var sanitizeHtml = require('sanitize-html'); - -function loadGoogleAPI(window, callback) { - if (window.google) { - return process.nextTick(callback); - } - var head = document.getElementsByTagName('head')[0]; - var gScript = document.createElement('script'); - gScript.setAttribute('src', 'https://www.google.com/jsapi'); - gScript.onload = callback; - head.appendChild(gScript); -}; - -function getBlogFeeds(feedUrl, callback) { - if (window.google) { - var google = window.google; - google.load('feeds', '1', { - callback: function() { - var feed = new google.feeds.Feed(feedUrl); - feed.load(function(result) { - callback(formatBlogFeeds(result.feed)); - }); - } - }); - } -} - -function formatBlogFeeds(feeds) { - var featured = feeds.entries[0]; - var latestPosts = []; - var post; - for (var i = 1; i < 4; i++) { - post = feeds.entries[i]; - latestPosts.push({ - title: post.title, - publishedDate: post.publishedDate, - link: post.link - }); - } - return { - featuredPostData: { - title: featured.title, - author: featured.author, - publishedDate: featured.publishedDate, - contentSnippet: sanitizeHtml(featured.content, { - allowedTags: [] - }).split(' ').slice(0, 70).join(' ') + '...', - link: post.link - }, - latestPostsData: latestPosts - }; -} - -var loadBlogFeed = function(requestedComp, window, feedUrl, callback) { - loadGoogleAPI(window, function() { - if (requestedComp.isMounted()) { - getBlogFeeds(feedUrl, function(result) { - callback(result); - }); - } - }); -}; - -module.exports = loadBlogFeed; - +// TODO: Replace this with a real implementation. +module.exports = require('../test/browser/stub-blog-feed-loader'); diff --git a/package.json b/package.json index 94211dea0..ea6a9c109 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,6 @@ "react-ga": "^1.0.12", "react-router": "^0.13.2", "react-select": "0.4.6", - "sanitize-html": "^1.6.1", "should": "^5.1.0", "simplecrawler": "^0.5.2", "source-map-support": "^0.2.10", diff --git a/pages/home.jsx b/pages/home.jsx index 2be0aa9bb..425fd3c64 100644 --- a/pages/home.jsx +++ b/pages/home.jsx @@ -2,7 +2,6 @@ var React = require('react'); var Router = require('react-router'); var Link = Router.Link; var moment = require('moment'); -var sanitizeHtml = require('sanitize-html'); var HeroUnit = require('../components/hero-unit.jsx'); var Blockquote = require('../components/blockquote.jsx'); @@ -14,7 +13,7 @@ var IconButton = require('../components/icon-button.jsx'); var config = require('../lib/config'); -var blogFeedLoader = require('../lib/blog-feed-loader'); +var loadBlogPosts = require('../lib/blog-feed-loader'); var CaseStudies = React.createClass({ render: function() { @@ -88,26 +87,33 @@ var LatestPosts = React.createClass({ }); var BlogSection = React.createClass({ + getDefaultProps: function() { + return { + loadBlogPosts: loadBlogPosts + }; + }, getInitialState: function() { return { - featuredPostData: { + featuredPost: { title: "", author: "", publishedDate: "", contentSnippet: "", link: "" }, - latestPostsData: [] + latestPosts: [] } }, componentDidMount: function() { - var self = this; - blogFeedLoader(this, window, "https://blog.webmaker.org/tag/teachtheweb/feed", function(data) { - self.setState({ - featuredPostData: data.featuredPostData, - latestPostsData: data.latestPostsData + this.props.loadBlogPosts(function(data) { + if (!this.isMounted()) { + return; + } + this.setState({ + featuredPost: data.featuredPosts, + latestPosts: data.latestPosts }); - }); + }.bind(this)); }, render: function() { return ( @@ -119,10 +125,10 @@ var BlogSection = React.createClass({