Inital commit
This commit is contained in:
commit
4e5b4cc2fc
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
bin/
|
76
src/upload.raku
Executable file
76
src/upload.raku
Executable file
|
@ -0,0 +1,76 @@
|
|||
#!/usr/bin/env raku
|
||||
|
||||
use paths;
|
||||
use File::Temp;
|
||||
use DOM::Tiny;
|
||||
|
||||
# Find and collect all of our idris files
|
||||
my @idris-files =
|
||||
paths("src", :file(-> $a {$a.ends-with(".idr") || $a.ends-with(".md")}))
|
||||
.map: *.IO.relative("src/".IO);
|
||||
|
||||
|
||||
# Do a pack clean build so we can find the ttms
|
||||
exit -1 unless run <pack clean>;
|
||||
exit -1 unless run <pack build>;
|
||||
|
||||
# find our ttc folder
|
||||
my $build-path = "build/ttc/".IO.dir[0];
|
||||
|
||||
# Get a temporary directory to work in
|
||||
my $dir = tempdir().IO;
|
||||
|
||||
my constant $background-css = '
|
||||
body {
|
||||
color: #b9b9b9;
|
||||
background-color: #181818;
|
||||
}
|
||||
';
|
||||
|
||||
# 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
|
||||
}
|
||||
|
||||
# Renders the file at the given location to the temporary directory
|
||||
sub render-idris-file($idr) {
|
||||
say "Converting $idr";
|
||||
# Figure out our file paths
|
||||
my $source-file = IO::Path.new($idr, :CWD("src/".IO)).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",
|
||||
$source-file, $ttm-file, :out;
|
||||
my $contents = $katla.out.slurp :close;
|
||||
$contents = stylize $contents;
|
||||
# Make sure the directory exists and write the contents to it
|
||||
$out-file.dirname.IO.mkdir;
|
||||
$out-file.spurt: $contents;
|
||||
}
|
||||
|
||||
# For each of our idris files, find the ttm, and generate the output in the
|
||||
# temporary directory
|
||||
for @idris-files.hyper -> $idr {
|
||||
render-idris-file $idr;
|
||||
# TODO : Build index
|
||||
}
|
||||
|
||||
# Upload files
|
||||
run <rsync -rvh>, "$dir/",
|
||||
"ubuntu@129.153.226.221:/var/www/static.stranger.systems/AoC/2024";
|
||||
|
Loading…
Reference in a new issue