forked from mozilla/learning.mozilla.org
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from toolness/decouple-new-homepage-from-googs
Add a stub/fake blog feed loader and use it for now.
- Loading branch information
Showing
4 changed files
with
50 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var FAKE_POSTS = { | ||
"featuredPosts": { | ||
"title": "What’s next for Thimble?", | ||
"author": "Hannah Kane", | ||
"publishedDate": "Tue, 12 May 2015 10:47:33 -0700", | ||
"contentSnippet": "Last week we announced that Thimble will soon be moving over to our new site for people who teach the web, teach.mozilla.org. We also shared that Professor David Humphrey and a team of students from Seneca College have been working to make Thimble an even more powerful teaching, learning, and development tool.\nWe wanted to follow up with more specifics about what you can expect from the new Thimble:\n\nOver the next...", | ||
"link": "https://blog.webmaker.org/whats-next-for-thimble" | ||
}, | ||
"latestPosts": [ | ||
{ | ||
"title": "What’s next for Webmaker tools", | ||
"publishedDate": "Mon, 04 May 2015 11:53:23 -0700", | ||
"link": "https://blog.webmaker.org/whats-next-for-webmaker-tools" | ||
}, | ||
{ | ||
"title": "Understanding Web Literacy within the Web Journey", | ||
"publishedDate": "Tue, 21 Apr 2015 08:04:56 -0700", | ||
"link": "https://blog.webmaker.org/understanding-web-literacy-within-the-web-journey" | ||
}, | ||
{ | ||
"title": "Learning Through Making: The Best Kind of Education", | ||
"publishedDate": "Thu, 16 Apr 2015 12:04:55 -0700", | ||
"link": "https://blog.webmaker.org/learning-through-making-the-best-kind-of-education" | ||
} | ||
] | ||
}; | ||
|
||
module.exports = function(cb) { | ||
process.nextTick(cb.bind(null, FAKE_POSTS)); | ||
}; |