Skip to content

Instantly share code, notes, and snippets.

@samguergen
Last active January 19, 2019 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samguergen/bd2362afccd1a342ce69d4116413733f to your computer and use it in GitHub Desktop.
Save samguergen/bd2362afccd1a342ce69d4116413733f to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<div class="jumbotron" ng-init="fetchRecentBlogURLs()">
<div class="container section-content">
<h1 style="text-align:center;font-size:50px">
<a href="http://blog.itnamerica.org/">ITN<em>America</em> Blog</a>
</h1>
<div class="row">
<div class="col-md-4 mt-25" ng-repeat="entry in blogEntries">
<div class="blog-thumbnail">
<a ng-href="{{entry.blogURL}}">
<img ng-src="{{entry.imgURL}}" alt="recent blog post thumbnail image"/>
<h4 style="text-align:center;color:black">{{entry.title}}</h4>
</a>
</div>
</div>
</div>
</div>
</div>
<script>
(function () {
var myApp = angular.module('myApp', []);
myApp.controller('MainCtrl', ['$scope, function($scope){
$scope.fetchRecentBlogURLs = function(){
$http.get('/getBlogContent', {
params: {
blogURL: 'http://blog.itnamerica.org/'
}
}).then(function(response) {
$scope.homepageBlogContent = response.data;
$scope.blogURLs = [];
var blogNumber = 3;
var idx;
if ($scope.homepageBlogContent.indexOf('<h1 class="entry-title"><a href="') !== -1){
for (var num=0; num<blogNumber; num++){
idx = $scope.homepageBlogContent.indexOf('<h1 class="entry-title"><a href="');
var storeBlogURL = [];
for (var i=33; i<$scope.homepageBlogContent.length; i++){
if ($scope.homepageBlogContent[idx+i] === ' ' && $scope.homepageBlogContent[idx+i+1] === 'r' && $scope.homepageBlogContent[idx+i+2] === 'e' && $scope.homepageBlogContent[idx+i+3] === 'l' && $scope.homepageBlogContent[idx+i+4] === '='){
break;
}
storeBlogURL.push($scope.homepageBlogContent[idx+i]);
}
storeBlogURL = storeBlogURL.slice(0, -1).join('').toString();
$scope.blogURLs.push(storeBlogURL);
$scope.homepageBlogContent = $scope.homepageBlogContent.slice(idx+33);
}
}
$scope.getContentForEachBlogURL();
})
};
$scope.getContentForEachBlogURL = function(){
for (var x = 0; x < $scope.blogURLs.length; x++) {
$scope.getBlogContent($scope.blogURLs[x]);
}
};
$scope.getBlogContent = function(url){
$http.get('/getBlogContent', {
params: {
blogURL: url
}
}).then(function(response) {
$scope.blogContent = response.data;
//get title of post for thumbnail
if ($scope.blogContent.indexOf('<h1 class="entry-title"') !== -1){
var idx = $scope.blogContent.indexOf('<h1 class="entry-title"');
var store = [];
for (var i=24; i<$scope.blogContent.length; i++){
if ($scope.blogContent[idx+i] === '<'){
break;
}
store.push($scope.blogContent[idx+i]);
}
store = store.join('').toString();
//if title tag has other attr, strip them off
$scope.entryTitle = store.substr(store.indexOf(">")+1,store.length)
console.log('entry title is ', $scope.entryTitle);
}
//get img of post for thumnail
if ($scope.blogContent.indexOf('<img class=') !== -1){
var idx = $scope.blogContent.indexOf('<img class=');
var store2 = [];
for (var i=12; i<$scope.blogContent.length; i++){
if ($scope.blogContent[idx+i] === 'a' && $scope.blogContent[idx+i+1] === 'l' && $scope.blogContent[idx+i+2] === 't' || $scope.blogContent[idx+i] === '>'){
break;
}
store2.push($scope.blogContent[idx+i]);
}
$scope.entryImgURL = store2.join('').toString();
$scope.entryImgURL = $scope.entryImgURL.match(/\bhttps?:\/\/\S+/gi);
$scope.entryImgURL = $scope.entryImgURL.toString().slice(0,-1);
}
$scope.blogEntries.push({
title: $scope.entryTitle,
imgURL: $scope.entryImgURL,
blogURL: url
});
});
};
]})
})();
</script>
</html>
@samguergen
Copy link
Author

samguergen commented Jan 19, 2019

A gist for displaying a thumbnail carousel of the 3 latest blog entries in your Wordpress blog.

screen shot 2019-01-19 at 2 22 38 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment