Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
92db004
commit 8885cb6
Showing
8 changed files
with
227 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
*~ | ||
.sass-cache | ||
.precomp | ||
*.map | ||
assets/sass/main.css | ||
hypnotoad.pid | ||
assets/assetpack.db | ||
assets/cache/ | ||
pull-password | ||
.precomp | ||
/test.p6 | ||
/out.html |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/env perl | ||
|
||
use lib qw<lib>; | ||
use Mojolicious::Lite; | ||
use Mojo::UserAgent; | ||
use Mojo::File qw/path/; | ||
use Mojo::Util qw/trim/; | ||
use Time::Moment; | ||
use RakudoOrg::Posts; | ||
|
||
my $posts = RakudoOrg::Posts->new; | ||
my $ua = Mojo::UserAgent->new; | ||
|
||
app->config({ hypnotoad => { listen => ['http://*:4242'], proxy => 1 } }); | ||
|
||
# plugin 'AssetPack' => { pipes => [qw/Sass JavaScript Combine/] }; | ||
# app->asset->process('app.css' => 'sass/main.scss'); | ||
# app->asset->process('app.js' => qw{ | ||
# js/ie10-viewport-bug-workaround.js | ||
# js/codemirror/codemirror.min.js | ||
# js/codemirror/perl6-mode.js | ||
# js/main.js | ||
# }); | ||
|
||
### Routes | ||
get '/' => sub { | ||
my $c = shift; | ||
$c->stash(posts => $posts->all); | ||
} => 'home'; | ||
|
||
get '/post/#post' => sub { | ||
my $c = shift; | ||
my ($meta, $markdown, $html) = $posts->load($c->param('post')); | ||
$html or return $c->reply->not_found; | ||
|
||
$c->stash(%$meta, post => $html, title => $meta->{title}); | ||
} => 'post'; | ||
|
||
any $_ => sub { | ||
my $c = shift; | ||
my $posts = [ map +{ %$_ }, @{ $posts->all } ]; | ||
$_->{date} = blog_date_to_feed_date($_->{date}) for @$posts; | ||
|
||
my $blog_last_updated_date = $posts->[0]{date}; | ||
$c->stash( | ||
posts => $posts, | ||
last_update => $blog_last_updated_date, | ||
template => 'feed', | ||
format => 'xml', | ||
); | ||
}, ($_ eq '/feed' ? 'feed' : ()) | ||
for '/feed', '/feed/', '/feed/index', '/atom', '/atom/', '/atom/index'; | ||
|
||
get '/pull/*password' => sub { | ||
my $c = shift; | ||
|
||
return $c->reply->not_found | ||
unless $c->param('password') eq trim path('pull-password')->slurp; | ||
|
||
$c->render( | ||
text => "Pulled!\n" . `git pull`, | ||
format => 'txt', | ||
); | ||
}; | ||
|
||
app->start; | ||
|
||
sub blog_date_to_feed_date { | ||
my $date = shift; | ||
return Time::Moment->from_string("${date}T00:00:00Z") | ||
->strftime("%a, %d %b %Y %H:%M:%S %z"); | ||
} | ||
|
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package RakudoOrg::Posts; | ||
|
||
use base 'Mojo::Base'; | ||
|
||
use Text::MultiMarkdown qw/markdown/; | ||
use File::Glob qw/bsd_glob/; | ||
use Mojo::File qw/path/; | ||
use Mojo::Util qw/decode encode xml_escape/; | ||
|
||
sub all { | ||
my @posts = bsd_glob 'post/*.md'; | ||
s/\.md$// for @posts; | ||
my @return; | ||
for (@posts) { | ||
my ($meta) = process(decode 'UTF-8', path("$_.md")->slurp); | ||
next if $meta->{draft}; | ||
push @return, { | ||
date => $meta->{date}, | ||
title => $meta->{title}, | ||
desc => $meta->{desc}, | ||
post => (substr $_, length 'post/'), | ||
}; | ||
} | ||
return [ sort { $b->{date} cmp $a->{date} } @return ]; | ||
} | ||
|
||
sub load { | ||
my ($self, $post) = @_; | ||
my $post_file = "post/$post.md"; | ||
return unless -f $post_file and -r _; | ||
my ($meta, $content) = process(decode 'UTF-8', path($post_file)->slurp); | ||
return $meta, markdown $content; | ||
} | ||
|
||
sub process { | ||
my $post = shift; | ||
my %meta; | ||
$meta{$1} = $2 while $post =~ s/^%%\s*(\w+)\s*:\s*([^\n]+)\n//; | ||
$post =~ s/^```$//gm; | ||
return \%meta, $post; | ||
} | ||
|
||
1; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/sh | ||
morbo -l 'http://*:4242' -w assets -w templates -w lib app.pl | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" | ||
xmlns:content="http://purl.org/rss/1.0/modules/content/" | ||
xmlns:wfw="http://wellformedweb.org/CommentAPI/" | ||
xmlns:dc="http://purl.org/dc/elements/1.1/" | ||
xmlns:atom="http://www.w3.org/2005/Atom" | ||
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" | ||
xmlns:slash="http://purl.org/rss/1.0/modules/slash/" | ||
xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/" | ||
> | ||
<channel> | ||
<title>Rakudo Perl 6 Compiler</title> | ||
<atom:link href="<%= url_for('feed')->to_abs %>" | ||
rel="self" type="application/rss+xml" /> | ||
<link><%= url_for('home')->to_abs %></link> | ||
<description>Rakudo Perl 6 Compiler</description> | ||
<lastBuildDate><%= $last_update %></lastBuildDate> | ||
<language>en</language> | ||
<image> | ||
<url><%= url_for('/assets/logo.png')->to_abs %></url> | ||
<title>Perl 6 Compiler</title> | ||
<link><%= url_for('home')->to_abs %></link> | ||
</image> | ||
|
||
% for my $post (@$posts) { | ||
<item> | ||
<title><%= $post->{title} %></title> | ||
<link><%= url_for(post => $post->{post})->to_abs %></link> | ||
<pubDate><%= $post->{date} %></pubDate> | ||
<guid isPermaLink="true"><%= | ||
url_for(post => $post->{post})->to_abs %></guid> | ||
<description><![CDATA[<%= $post->{desc} %>]]></description> | ||
</item> | ||
% } | ||
</channel> | ||
</rss> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
% layout 'default'; | ||
% title 'Rakudo Perl 6 Compiler'; | ||
|
||
% for my $p ( @$posts ) { | ||
<div class="blog-post"> | ||
<h2 class="blog-post-title" | ||
><a href="<%= $p->{link} %>"><%= $p->{title} %></a></h2> | ||
<p class="blog-post-meta"><%= $p->{date} %></p> | ||
<p class="blog-post"><%= $p->{desc} =%></p> | ||
</div> | ||
% } | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<meta property="og:image" | ||
content="<%= url_for('/assets/logo.png')->to_abs %>"> | ||
<meta name="twitter:image" | ||
content="<%= url_for('/assets/logo.png')->to_abs %>"> | ||
<title><%= $title %> | ||
- Rakudo Compiler for Perl 6 Programming Language</title> | ||
</head> | ||
<body> | ||
<div class="blog-masthead"> | ||
<div class="container"> | ||
<nav class="blog-nav"> | ||
<a class="blog-nav-item <%= stash('active-page')//'' eq 'home' ? 'active' : '' %>" href="/">Home</a> | ||
<a class="blog-nav-item feed-nav" | ||
href="<%= url_for 'feed' %>">Feed</a> | ||
</nav> | ||
</div> | ||
</div> | ||
|
||
<div class="bg"> | ||
<div class="container"> | ||
<div class="blog-header"> | ||
<h1 class="blog-title"><%= $title | ||
// 'Rakudo Compiler for Perl 6 Programming Language' %></h1> | ||
</div> | ||
<div class="row"> | ||
<div class="col-sm-12 blog-main"> | ||
<%= content %> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<footer class="blog-footer"> | ||
<p class="icons"> | ||
<a href="https://perl6.org" class="powered-by" | ||
title="Use Perl 6">Use Perl 6.</a> | ||
<a href="https://github.com/perl6/rakudo.org" class="fork-it" | ||
title="Fork this blog">Repository for this site.</a> | ||
</p> | ||
</footer> | ||
</body> | ||
</html> | ||
|