/
crank
executable file
·87 lines (71 loc) · 2.06 KB
/
crank
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/perl -w
use strict;
use warnings;
eval 'use Carp::Always'; # Not everyone has it
use Getopt::Long;
use File::Slurp;
use Encode qw(decode_utf8);
use Text::Markdown ();
use Template ();
use Template::Constants qw( :debug :chomp );
my $sourcepath = 's';
my $buildpath = 'build';
GetOptions(
'sourcepath:s' => \$sourcepath,
'buildpath:s' => \$buildpath,
) or exit;
-d $buildpath && -w $buildpath or die;
my $pages = [
index => 'Home',
perl => 'Perl',
regexes => 'Regexes',
# asp => 'ASP',
# coldfusion => 'ColdFusion',
# csharp => 'C#',
# delphi => 'Delphi',
# dotnet => '.NET',
# java => 'Java',
# perl => 'Perl',
# php => 'PHP',
# postgresql => 'PostgreSQL',
# python => 'Python',
# ruby => 'Ruby',
# scheme => 'Scheme',
];
MAIN: {
my $m = Text::Markdown->new;
my @sidelinks;
my %tt_defaults = (
INCLUDE_PATH => [ qw( tt ) ],
OUTPUT_PATH => $buildpath,
DEBUG => DEBUG_UNDEF,
TRIM => CHOMP_ALL,
PRE_CHOMP => 1,
POST_CHOMP => 1,
ENCODING => 'utf8',
);
my $tt = Template->new( \%tt_defaults );
my @pages = @{$pages};
while ( @pages ) {
my ($section,$desc) = splice( @pages, 0, 2 );
my $path = ($section eq 'index') ? './' : "./$section.html";
push( @sidelinks, {
path => $path,
text => $desc,
} );
}
my $vars = {
sidelinks => \@sidelinks,
};
@pages = @{$pages};
while ( @pages ) {
my ($section,$desc) = splice( @pages, 0, 2 );
my $source = read_file( "$sourcepath/$section.mkd" );
my $html = $m->markdown( $source );
$html =~ s{<code>\n}{<code>}smxg;
$vars->{body} = $html;
$vars->{currlang} = ( $desc eq 'Home' ) ? '' : $desc;
$tt->process( 'page.ttml', $vars, "$section.html", { binmode => ':encoding(UTF-8)' } )
|| die sprintf("file: %s\nerror: %s\n", "$section.html", $tt->error);
}
}