Skip to content

Instantly share code, notes, and snippets.

@dougshamoo
Created July 13, 2015 21:55
Show Gist options
  • Select an option

  • Save dougshamoo/3f444b38b1f6e1d3f372 to your computer and use it in GitHub Desktop.

Select an option

Save dougshamoo/3f444b38b1f6e1d3f372 to your computer and use it in GitHub Desktop.
Camper News

Camper News

Uses FreeCodeCamp's Camper News Hot Stories API to display a stylized version of Camper News.

A Pen by dougtslug on CodePen.

License.

<body ng-app="camperNews" ng-controller="newsController">
<div class="jumbotron">
<h1>Free Code Camp:</h1>
<h2>Camper News</h2>
</div>
<div class="container columns">
<div class="story-box" ng-repeat="story in news | orderBy: '-upVotes.length'">
<div><img ng-src="{{story.author.picture}}"></div>
<div class="headline"><a ng-href="{{story.link}}" target="_blank">{{story.headline}}</a></div>
<br/>
<div class="upvotes">+{{story.upVotes.length}}</div>
<div class="comments">
<a ng-href="{{getCommentUrl(story.storyLink)}}">{{story.comments.length}} comments</a>
</div>
</div>
</div>
</body>
var app = angular.module('camperNews', ['ngAnimate']);
app.controller('newsController', function($scope, newsService) {
$scope.init = function() {
$scope.getNews();
};
$scope.getNews = function() {
newsService.getNews().then(function(res) {
$scope.news = res.data;
});
};
$scope.getCommentUrl = function(storyLink) {
return storyUrl + storyLink.split(' ').join('-');
}
$scope.init();
});
app.service('newsService', function($http, $q) {
this.getNews = function() {
return $http.get(apiUrl).then(function(res) {
return res;
})
};
});
var apiUrl = 'http://www.freecodecamp.com/stories/hotStories';
var storyUrl = 'http://www.freecodecamp.com/news/'
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.14/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.14/angular-animate.min.js"></script>
@import url(http://fonts.googleapis.com/css?family=Slabo+27px);
$font-stack: 'Slabo 27px', serif;
$back-color: #FF5722;
$box-color: lighten(grey, 45);
@mixin column-count($col) {
-webkit-column-count: $col;
-moz-column-count: $col;
column-count: $col;
}
@mixin column-gap($gap) {
-webkit-column-gap: $gap;
-moz-column-gap: $gap;
column-gap: $gap;
}
.columns {
@include column-count(4);
@include column-gap(0);
}
body {
font-family: $font-stack;
background-color: $back-color;
.jumbotron {
text-align: center;
background-color: $box-color;
margin-top: 30px;
border-top: 3px solid darken($back-color, 20);
border-bottom: 3px solid darken($back-color, 20);
}
.container {
.story-box {
border: 1px solid darken($back-color, 20);
background-color: $box-color;
padding: 10px;
margin: 0 2px 4px 2px;
position: relative;
/* Important to keep boxes from being split between columns */
-webkit-column-break-inside: avoid;
page-break-inside: avoid;
img {
width: 100%;
margin-bottom: 5px;
}
.headline {
font-weight: bold;
text-align: center;
}
.upvotes {
position: absolute;
left: 5px;
bottom: 5px;
}
.comments {
position: absolute;
right: 5px;
bottom: 5px;
}
}
}
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
<link href="//cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.3/animate.min.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment