Skip to content

Commit

Permalink
Add twitter text parsing, update dependencies
Browse files Browse the repository at this point in the history
Add twitter text parsing using “twitter-text” to autoLink the hashtags,
mentions and links from the tweets.

Resolve #3.
  • Loading branch information
carloscuesta committed Dec 28, 2015
1 parent 7ef48e4 commit 13a2aa4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
"compression": "^1.6.0",
"dotenv": "^1.2.0",
"express": "^4.13.3",
"ghost": "^0.7.3",
"form-data": "^1.0.0-rc3",
"ghost": "^0.7.4",
"jade": "^1.11.0",
"memory-cache": "^0.1.4",
"node-fetch": "^1.3.3",
"node-sass-middleware": "^0.9.7",
"oauth": "^0.9.14"
"oauth": "^0.9.14",
"twitter-text": "^1.13.2"
},
"devDependencies": {
"mocha": "^2.3.4",
Expand Down
4 changes: 3 additions & 1 deletion src/app/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if (process.env.NODE_ENV === 'development') {

var GithubApiClient = require('./scripts/githubapiclient'),
TwitterApiClient = require('./scripts/twitterapiclient'),
GhostApiClient = require('./scripts/ghostapiclient'),
cache = require('memory-cache'),
staticData = require('./data/staticdata');

Expand All @@ -26,9 +27,10 @@ exports.index = function(req, res) {
});

Promise.all([ghUserCCStars, userTimeline]).then(function(data) {
var tweets = TwitterApiClient.parseTweets(data[1]);
res.render('views/index', {
githubData: data[0],
twitterData: data[1],
twitterData: tweets,
me: staticData.me,
site: staticData.site,
social: staticData.social,
Expand Down
14 changes: 13 additions & 1 deletion src/app/scripts/twitterapiclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require('dotenv').load();

var ApiClient = require('./apiclient'),
twitterParse = require('twitter-text'),
CacheApiClient = require('./cache');

var TwitterApiClient = (function() {
Expand All @@ -24,8 +25,19 @@ var TwitterApiClient = (function() {
return CacheApiClient.validate.call(_ApiClient,'/statuses/user_timeline.json', params);
};

var parseTweets = function(tweets) {
var jsonTweets = [];

for (var i = 0; i < tweets.length; i++) {
jsonTweets.push(twitterParse.autoLink(tweets[i].text));
}

return jsonTweets;
};

return {
getUserTimeline: getUserTimeline
getUserTimeline: getUserTimeline,
parseTweets: parseTweets
};

})();
Expand Down
2 changes: 1 addition & 1 deletion src/app/templates/_includes/_sections/_twitter.jade
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ section.twitter
.row
h3 Twitter
-each tweet in twitterData
p #{tweet.text}
p !{tweet}

0 comments on commit 13a2aa4

Please sign in to comment.