I have a page on GitHub: https://jacoby.github.io/
Early in my playing with Bootstrap, I made this as a way to begin to play with it. It is about as simple a GitHub API to LWP to Template Toolkit to Bootstrap tool as I could have written. I'm now thinking about how to make this prettier, but for now, it's what I use to generate, when I remember to redo my GitHub page. Learn and enjoy.
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
#!/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> |
No comments:
Post a Comment