Skip to content

Instantly share code, notes, and snippets.

@jacoby
Created July 13, 2017 15:12
Show Gist options
  • Save jacoby/5f6eb8d051f8ad3ad8b8a4f9ae1e068f to your computer and use it in GitHub Desktop.
Save jacoby/5f6eb8d051f8ad3ad8b8a4f9ae1e068f to your computer and use it in GitHub Desktop.
Pulls my Github repos and puts them into a web page
#!/usr/bin/env perl
## ## ## ## ## ##
## ## ## ## ##
## #### ## #### ## # ## ## #### ## ### # ## ##
## ## ## ## ## ##### ## ## ## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
## #### ## ## ## ## ## # #### ## ### ## #### ##
## ## ##
## #### ##
# This program pulls my current public repos from GitHub and formats them
# to be my GitHub.io index page.
use feature qw{ say state } ;
use strict ;
use warnings ;
use utf8 ;
use Data::Dumper ;
use LWP::UserAgent ;
use JSON ;
use Template ;
my $url = 'https://api.github.com/users/jacoby/repos' ;
my $agent = LWP::UserAgent->new() ;
my $r = $agent->get( $url, type => 'public', ) ;
if ( $r->is_success ) {
my $content = $r->content ;
my $repos = decode_json($content) ;
my @sorted = sort { $b->{updated_at} cmp $a->{updated_at} } @$repos ;
my $data
= { repos => \@sorted, json => $content, dump => Dumper $repos } ;
my $tt = join '', <DATA> ;
my $config = {
ABSOLUTE => 1, # Allow absolute file names
INTERPOLATE => 0, # Allow variables with $var or ${var} , no for JS
POST_CHOMP => 0, # Chomp whitespace after tags
PRE_CHOMP => 0, # ... and before
RELATIVE => 1, # Allow relative file names
TRIM => 1, # Trim leading/following white space
} ;
my $template = Template->new($config) ;
my $output ;
$template->process( \$tt, $data, \$output )
|| croak $template->error() ;
say $output ;
}
__DATA__
<!doctype html>
<html>
<head>
<title> Dave Jacoby </title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
</head>
<body>
<h1> Dave Jacoby </h1>
<!-- repos -->
<h2 class="col-md-12"> Repos </h2>
[% FOR repo IN repos %][% IF repo.fork == 0 %]
<div class="col-md-4">
<h3>
<a href="[% IF repo.homepage%][% repo.homepage %][% ELSE %][% repo.html_url %][% END %]"
target="_blank">[% repo.name %]</a>
</h3>
[% IF repo.fork == 1 %] fork [% END %]
[% IF repo.provate == 1 %] private [% END %]
<div> [% repo.language %] - [% repo.updated_at %] </div>
<p>[% repo.description %]</p>
</div>
[% END %][% END %]
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"
integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script>
var host = "jacoby.github.io";
if ((host == window.location.host) && (window.location.protocol != "https:"))
window.location.protocol = "https";
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment