Basic index generation
This commit is contained in:
parent
9909840b65
commit
a06df05580
|
@ -3,6 +3,7 @@
|
||||||
use paths;
|
use paths;
|
||||||
use File::Temp;
|
use File::Temp;
|
||||||
use DOM::Tiny;
|
use DOM::Tiny;
|
||||||
|
use HTML::Lazy (:ALL);
|
||||||
|
|
||||||
my $build-path;
|
my $build-path;
|
||||||
my $dir;
|
my $dir;
|
||||||
|
@ -52,6 +53,49 @@ sub render-idris-file($idr) {
|
||||||
# Make sure the directory exists and write the contents to it
|
# Make sure the directory exists and write the contents to it
|
||||||
$out-file.dirname.IO.mkdir;
|
$out-file.dirname.IO.mkdir;
|
||||||
$out-file.spurt: $contents;
|
$out-file.spurt: $contents;
|
||||||
|
# Return the out-file
|
||||||
|
$out-file
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add a path to our index hash
|
||||||
|
my method add-path(%index: $path, $value) {
|
||||||
|
# Split the path up
|
||||||
|
my @parts = $path.split("/");
|
||||||
|
my $head = @parts[0];
|
||||||
|
@parts = @parts[1..*-1];
|
||||||
|
if @parts.elems == 0 {
|
||||||
|
%index{$head} = $value;
|
||||||
|
} else {
|
||||||
|
if !%index{$head} {
|
||||||
|
%index{$head} = %();
|
||||||
|
}
|
||||||
|
%index{$head}.&add-path(join('/', @parts), $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Render the index to html
|
||||||
|
my method render-index(%index:) {
|
||||||
|
my @elements = [];
|
||||||
|
for %index.keys -> $key {
|
||||||
|
say "";
|
||||||
|
say $key;
|
||||||
|
say %index{$key} ~~ Str;
|
||||||
|
say %index{$key};
|
||||||
|
say "";
|
||||||
|
given %index{$key} {
|
||||||
|
when Str {
|
||||||
|
my $x = $_;
|
||||||
|
@elements.push(
|
||||||
|
li(Map,
|
||||||
|
a({ :href($x) }, text($key))));
|
||||||
|
}
|
||||||
|
default {
|
||||||
|
my $rest = $_.&render-index();
|
||||||
|
@elements.push(li(Map, text($key), $rest));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ul(Map, @elements)
|
||||||
}
|
}
|
||||||
|
|
||||||
sub MAIN(
|
sub MAIN(
|
||||||
|
@ -84,11 +128,24 @@ sub MAIN(
|
||||||
|
|
||||||
# For each of our idris files, find the ttm, and generate the output in the
|
# For each of our idris files, find the ttm, and generate the output in the
|
||||||
# temporary directory
|
# temporary directory
|
||||||
|
my %index = %();
|
||||||
for @idris-files.hyper :batch(1) -> $idr {
|
for @idris-files.hyper :batch(1) -> $idr {
|
||||||
render-idris-file $idr;
|
my $out = render-idris-file $idr;
|
||||||
# TODO : Build index
|
%index.&add-path($idr, $out.relative($dir)) when $out ~~ IO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $index = %index.&render-index();
|
||||||
|
my $title = $*CWD.basename;
|
||||||
|
$index = html-en
|
||||||
|
head(Map,
|
||||||
|
title(Map, text($title))
|
||||||
|
),
|
||||||
|
body(Map,
|
||||||
|
$index
|
||||||
|
);
|
||||||
|
|
||||||
|
"$dir/index.html".IO.spurt(render($index));
|
||||||
|
|
||||||
# Figure out our destination
|
# Figure out our destination
|
||||||
my $dest = do if $dest_dir ~~ Str {
|
my $dest = do if $dest_dir ~~ Str {
|
||||||
$dest_dir
|
$dest_dir
|
||||||
|
|
Loading…
Reference in a new issue