From 4e5b4cc2fc227cfdfbf546eb3d5db1e2efb2edfb Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Fri, 20 Dec 2024 07:56:28 +0000 Subject: [PATCH] Inital commit --- .gitignore | 1 + src/upload.raku | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 .gitignore create mode 100755 src/upload.raku diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e660fd9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +bin/ diff --git a/src/upload.raku b/src/upload.raku new file mode 100755 index 0000000..21a040f --- /dev/null +++ b/src/upload.raku @@ -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 ; +exit -1 unless run ; + +# 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/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 , "$dir/", +"ubuntu@129.153.226.221:/var/www/static.stranger.systems/AoC/2024"; +