Improve build-book script

This commit is contained in:
Nathan McCarty 2025-01-27 21:02:07 -05:00
parent e00ec274ca
commit e91db14c11

View file

@ -23,7 +23,7 @@ sub not-ignored($path) {
# Copy a file from the current directory to the temporary directory, preserving # Copy a file from the current directory to the temporary directory, preserving
# realtive path. Resolves symlinks in source, but does not reflect symlink # realtive path. Resolves symlinks in source, but does not reflect symlink
# resoultion in the output path # resoultion in the output path
sub cp-temp($src) { sub copy-to-dest($src) {
my $src-path = do given $src { my $src-path = do given $src {
when Str { when Str {
$src.IO $src.IO
@ -45,42 +45,16 @@ sub cp-temp($src) {
$src-path.resolve.copy: $output-path; $src-path.resolve.copy: $output-path;
} }
# Invoke katla on a source file, streaming its output to the temporary directory # Special handling for our readme file, we need to butcher up it's links
sub katla($src, $ttc-src) { my $readme-contents = 'README.md'.IO.slurp;
# Run katla and collect the output $readme-contents ~~ s:g/'src/'//;
my $katla = run 'katla', 'markdown', $src, $ttc-src, :out; my $readme-dest = $tempdir.add('src/README.md');
my $output = $katla.out.slurp(:close); $readme-dest.parent.mkdir;
# TODO: Post process them to set themeing correctly $readme-dest.spurt: $readme-contents;
$output ~~ s:g/'<style>' .* '</style>'//;
$output ~~ s:g/'<br />'//;
$output ~~ s:g/'\\*'/*/;
$output ~~ s:g/'\\_'/_/;
$output ~~ s:g/'\\\\'/\\/;
$output ~~ s:g/'<code'/<pre><code/;
$output ~~ s:g/'</code>'/<\/code><\/pre>/;
$output ~~ s:g/'class="IdrisKeyword"'/class="hljs-keyword"/;
$output ~~ s:g/'class="IdrisModule"'/class="hljs-symbol hljs-emphasis"/;
$output ~~ s:g/'class="IdrisComment"'/class="hljs-comment"/;
$output ~~ s:g/'class="IdrisFunction"'/class="hljs-symbol"/;
$output ~~ s:g/'class="IdrisBound"'/class="hljs-name"/;
$output ~~ s:g/'class="IdrisData"'/class="hljs-title"/;
$output ~~ s:g/'class="IdrisType"'/class="hljs-type"/;
$output ~~ s:g/'class="IdrisNamespace"'/class="hljs-symbol hljs-emphasis"/;
# Spurt the output to the temporary directory
my $output-path = $tempdir.add: $src;
if !$output-path.parent.d {
$output-path.parent.mkdir;
}
$output-path.spurt($output);
}
# Copy our metadata files # Copy our metadata files
cp-temp "book.toml"; copy-to-dest "book.toml";
# TODO: Special Handling for the README so we don't need the symlink and the copy-to-dest "src/SUMMARY.md";
# links work
cp-temp "src/README.md";
cp-temp "src/SUMMARY.md";
# Katla over the source files # Katla over the source files
for paths("src", :file(*.&not-ignored)) -> $path { for paths("src", :file(*.&not-ignored)) -> $path {
@ -104,3 +78,38 @@ if $upload {
'ubuntu@static.stranger.systems:/var/www/static.stranger.systems/idris-by-contrived-example'; 'ubuntu@static.stranger.systems:/var/www/static.stranger.systems/idris-by-contrived-example';
die "rsync went bad" unless $rsync; die "rsync went bad" unless $rsync;
} }
# This function goes at the end because it breaks emacs fontification after it
# for some bizzare reason.
#
# Invoke katla on a source file, streaming its output to the temporary directory
sub katla($src, $ttc-src) {
# Run katla and collect the output
my $katla = run 'katla', 'markdown', $src, $ttc-src, :out;
my $output = $katla.out.slurp(:close);
# Post process them to set themeing correctly
# TODO: We need to remove the extra new line after the start of code blocks
# still
$output ~~ s:g/'<style>' .* '</style>'//;
$output ~~ s:g/'<br />'//;
$output ~~ s:g/'\\*'/*/;
$output ~~ s:g/'\\_'/_/;
$output ~~ s:g/'\\\\'/\\/;
$output ~~ s:g/'<code'/<pre><code/;
$output ~~ s:g/'</code>'/<\/code><\/pre>/;
$output ~~ s:g/'="IdrisKeyword"'/="hljs-keyword"/;
$output ~~ s:g/'="IdrisModule"'/="hljs-symbol hljs-emphasis"/;
$output ~~ s:g/'="IdrisComment"'/="hljs-comment"/;
$output ~~ s:g/'="IdrisFunction"'/="hljs-symbol"/;
$output ~~ s:g/'="IdrisBound"'/="hljs-name"/;
$output ~~ s:g/'="IdrisData"'/="hljs-title"/;
$output ~~ s:g/'="IdrisType"'/="hljs-type"/;
$output ~~ s:g/'="IdrisNamespace"'/="hljs-symbol hljs-emphasis"/;
# Spurt the output to the temporary directory
my $output-path = $tempdir.add: $src;
if !$output-path.parent.d {
$output-path.parent.mkdir;
}
$output-path.spurt($output);
}