Compare commits
10 commits
a06df05580
...
65377b3bc2
Author | SHA1 | Date | |
---|---|---|---|
65377b3bc2 | |||
ef56d2e00d | |||
32129d1794 | |||
ebefccec74 | |||
b019deea7a | |||
bc873863dc | |||
266025101e | |||
35ba371711 | |||
a4dcd397c9 | |||
57ac48e167 |
2 changed files with 97 additions and 26 deletions
23
src/katla.dhall
Normal file
23
src/katla.dhall
Normal file
|
@ -0,0 +1,23 @@
|
|||
{ font = "\\ttfamily"
|
||||
, space = " "
|
||||
, datacons = { style = ""
|
||||
, colour = "#ed4a46"}
|
||||
, typecons = { style = ""
|
||||
, colour = "#368aeb"}
|
||||
, bound = { style = ""
|
||||
, colour = "#dedede"}
|
||||
, function = { style = ""
|
||||
, colour = "#70b433"}
|
||||
, keyword = { style = "font-weight: bold;"
|
||||
, colour = "#3fc5b7"}
|
||||
, comment = { style = ""
|
||||
, colour = "#777777"}
|
||||
, hole = { style = "font-weight: bold;"
|
||||
, colour = "#dbb32d" }
|
||||
, namespce = { style = "font-style: italic;"
|
||||
, colour = "#dedede"}
|
||||
, postulte = { style = "font-weight: bold;"
|
||||
, colour = "#ed4a46"}
|
||||
, aModule = { style = "font-style: italic;"
|
||||
, colour = "#dedede"}
|
||||
}
|
100
src/upload.raku
100
src/upload.raku
|
@ -2,7 +2,6 @@
|
|||
|
||||
use paths;
|
||||
use File::Temp;
|
||||
use DOM::Tiny;
|
||||
use HTML::Lazy (:ALL);
|
||||
|
||||
my $build-path;
|
||||
|
@ -21,34 +20,34 @@ body {
|
|||
|
||||
# Stylize katla output
|
||||
sub stylize($katla-output) {
|
||||
my $dom = DOM::Tiny.parse($katla-output);
|
||||
# Insert our background css
|
||||
$dom.find('style')[*-1][*-1].prepend($background-css);
|
||||
# Undomify
|
||||
my $output = $dom.Str;
|
||||
# Apply regex edits to colorize existing elements
|
||||
$output =
|
||||
$output.match(/'color: darkgray'/).replace-with('color: #dedede')
|
||||
.match(/'color: lightgrey'/).replace-with('color: #777777')
|
||||
.match(/'color: yellow'/).replace-with('color: #3b3b3b')
|
||||
.match(/'color: gray'/).replace-with('color: #777777');
|
||||
$output
|
||||
$katla-output.match(/'color: darkgray'/).replace-with('color: #dedede')
|
||||
.match(/'color: lightgrey'/).replace-with('color: #777777')
|
||||
.match(/'color: yellow'/).replace-with('color: #3b3b3b')
|
||||
.match(/'color: gray'/).replace-with('color: #777777')
|
||||
.match(/'<style>'/).replace-with("<style>\n$background-css")
|
||||
}
|
||||
|
||||
# Renders the file at the given location to the temporary directory
|
||||
sub render-idris-file($idr) {
|
||||
sub render-idris-file($idr, $katla-config, $base-dir = "src/".IO) {
|
||||
say "Converting $idr";
|
||||
# Figure out our file paths
|
||||
my $source-file = IO::Path.new($idr, :CWD("src/".IO)).resolve;
|
||||
my $source-file = IO::Path.new($idr, :CWD($base-dir)).resolve;
|
||||
my $ttm-file =
|
||||
IO::Path.new($idr, :CWD($build-path)).extension("ttm").resolve;
|
||||
my $out-file = IO::Path.new($idr, :CWD($dir)).extension("html").resolve;
|
||||
# Bail out now if the ttm doesn't exist
|
||||
return unless $ttm-file ~~ :e;
|
||||
# Generate the html
|
||||
my $katla = run <katla html --config>, "katla/katla.dhall",
|
||||
# TODO: Stop relying on the config for now and just colorize it in regexs
|
||||
my $katla = run <katla html --config>, $katla-config,
|
||||
$source-file, $ttm-file, :out;
|
||||
my $contents = $katla.out.slurp :close;
|
||||
if $katla.exitcode != 0 {
|
||||
say "Katla Error:";
|
||||
say $contents;
|
||||
exit $katla.exitcode;
|
||||
}
|
||||
$contents = stylize $contents;
|
||||
# Make sure the directory exists and write the contents to it
|
||||
$out-file.dirname.IO.mkdir;
|
||||
|
@ -75,13 +74,24 @@ my method add-path(%index: $path, $value) {
|
|||
|
||||
# Render the index to html
|
||||
my method render-index(%index:) {
|
||||
# TODO sort these properly
|
||||
my @elements = [];
|
||||
for %index.keys -> $key {
|
||||
say "";
|
||||
say $key;
|
||||
say %index{$key} ~~ Str;
|
||||
say %index{$key};
|
||||
say "";
|
||||
my sub compare-with-numbers($a, $b) {
|
||||
my $a-match = $a ~~ /^(.+?)(\d*)(\.\w+)$/;
|
||||
my $b-match = $b ~~ /^(.+?)(\d*)(\.\w+)$/;
|
||||
($a-match[0] cmp $b-match[0]) || ($a-match[1].Int <=> $b-match[1].Int)
|
||||
}
|
||||
my sub compare-keys($key1, $key2) {
|
||||
if $key1 ~~ Str && $key2 ~~ Str {
|
||||
compare-with-numbers($key1, $key2)
|
||||
} elsif $key1 ~~ Str {
|
||||
Order::Less
|
||||
} else {
|
||||
Order::More
|
||||
}
|
||||
}
|
||||
my @keys = %index.keys.sort(&compare-keys);
|
||||
for @keys -> $key {
|
||||
given %index{$key} {
|
||||
when Str {
|
||||
my $x = $_;
|
||||
|
@ -98,9 +108,12 @@ my method render-index(%index:) {
|
|||
ul(Map, @elements)
|
||||
}
|
||||
|
||||
sub MAIN(
|
||||
$project_dir?, #= Base directory of project to upload, defaults to %*CWD
|
||||
#| Upload an entire project to its directory on the website
|
||||
multi MAIN(
|
||||
$project_dir?, #= Base directory of project to upload, defaults to $*CWD
|
||||
$dest_dir?, #= Destination directory on the remote
|
||||
$katla-config = #= Configuration file to pass to katla
|
||||
"/home/nathan/Projects/Idris/.scripts/src/katla.dhall",
|
||||
) {
|
||||
# cd to the projet directory if needed
|
||||
if $project_dir ~~ Str {
|
||||
|
@ -111,15 +124,30 @@ sub MAIN(
|
|||
my @idris-files =
|
||||
paths("src", :file(-> $a {$a.ends-with(".idr") || $a.ends-with(".md")}))
|
||||
.map: *.IO.relative("src/".IO);
|
||||
# Find and collect all of our test files
|
||||
my @test-files =
|
||||
paths("test/src", :file(-> $a {$a.ends-with(".idr") || $a.ends-with(".md")}))
|
||||
.map: *.IO.relative("test/src/".IO);
|
||||
say "Collected {@idris-files.elems} source files and {@test-files.elems} test files";
|
||||
|
||||
# Clean if there is more than one ttc folder, easiest way to locate the
|
||||
# correct one
|
||||
if "build/ttc".IO.dir.elems > 1 {
|
||||
my $ttc-path = "build/ttc".IO;
|
||||
if !($ttc-path ~~ :e) || $ttc-path.dir.elems != 1 {
|
||||
say "Couldn't locate ttc path in $ttc-path, rebuilding";
|
||||
# Do a pack clean build so we can find the ttms
|
||||
exit -1 unless run <pack clean>;
|
||||
exit -1 unless run <pack build>;
|
||||
}
|
||||
|
||||
# Now do the same for the test directory
|
||||
$ttc-path = "test/build/ttc".IO;
|
||||
if !($ttc-path ~~ :e) || $ttc-path.dir.elems != 1 {
|
||||
say "Couldn't locate tests ttc path in $ttc-path, rebuilding tests";
|
||||
exit -1 unless run <pack clean test/test.ipkg>;
|
||||
exit -1 unless run <pack build test/test.ipkg>;
|
||||
}
|
||||
|
||||
# find our ttc folder
|
||||
$build-path = "build/ttc/".IO.dir[0];
|
||||
|
||||
|
@ -129,12 +157,25 @@ sub MAIN(
|
|||
# For each of our idris files, find the ttm, and generate the output in the
|
||||
# temporary directory
|
||||
my %index = %();
|
||||
say "Processing idris files";
|
||||
for @idris-files.hyper :batch(1) -> $idr {
|
||||
my $out = render-idris-file $idr;
|
||||
my $out = render-idris-file $idr, $katla-config.IO;
|
||||
%index.&add-path($idr, $out.relative($dir)) when $out ~~ IO;
|
||||
}
|
||||
|
||||
my $index = %index.&render-index();
|
||||
# Now repeat for the test directory
|
||||
my %test-index = %();
|
||||
say "Processing test files";
|
||||
$build-path = "test/build/ttc/".IO.dir[0];
|
||||
for @test-files.hyper :batch(1) -> $idr {
|
||||
my $out = render-idris-file $idr, $katla-config.IO, "test/src".IO;
|
||||
%test-index.&add-path($idr, $out.relative($dir)) when $out ~~ IO;
|
||||
}
|
||||
|
||||
my %final-index = ("src" => %index, "test" => ("src" => %test-index));
|
||||
|
||||
say "Rendering index";
|
||||
my $index = %final-index.&render-index();
|
||||
my $title = $*CWD.basename;
|
||||
$index = html-en
|
||||
head(Map,
|
||||
|
@ -155,6 +196,13 @@ sub MAIN(
|
|||
"Projects/$snd/$fst"
|
||||
};
|
||||
|
||||
say "Uploading files to $remote:$web-base/$dest";
|
||||
|
||||
# Upload files
|
||||
run <rsync -rvh --mkpath --delete>, "$dir/", "$remote:$web-base/$dest";
|
||||
}
|
||||
|
||||
#| Upload the highlighting of a single idris file to a content addressable store
|
||||
#| directory
|
||||
multi MAIN('file') {
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue