basic idris rendering
This commit is contained in:
parent
56833369ce
commit
2c38910ccd
3 changed files with 44 additions and 9 deletions
1
blog
1
blog
|
@ -104,7 +104,6 @@ multi MAIN(
|
|||
#| Should the post be hidden from the archive?
|
||||
Bool :$hidden = False,
|
||||
) {
|
||||
say $default-ipkg;
|
||||
my $db = read-db $db-dir;
|
||||
my $id =
|
||||
$db.insert-post:
|
||||
|
|
|
@ -84,7 +84,10 @@ class PostDB {
|
|||
my $id-path = $by-id.add: "$id.html";
|
||||
$id-path.spurt: $html;
|
||||
for $post.all-slugs -> $slug {
|
||||
$by-slug.add($slug).symlink: $id-path;
|
||||
# remove the symlink if it already exists
|
||||
my $slug-path = $by-slug.add: $slug;
|
||||
$slug-path.unlink if $slug-path.l;
|
||||
$id-path.symlink: $slug-path;
|
||||
}
|
||||
}
|
||||
# Render the archive
|
||||
|
|
|
@ -2,6 +2,7 @@ use v6.e.PREVIEW;
|
|||
|
||||
use Pandoc;
|
||||
use JSON::Class:auth<zef:vrurg>;
|
||||
use File::Temp;
|
||||
|
||||
use DB::Post;
|
||||
|
||||
|
@ -11,7 +12,7 @@ unit class IdrisPost does Post is json(:pretty);
|
|||
|
||||
#| Marker for disambiguation between post types in json representation, the
|
||||
#| cheaty way
|
||||
has Bool:D $.idris = True;
|
||||
has Bool:D $.idris is json = True;
|
||||
|
||||
#| Location of the ipkg for the package containing the post
|
||||
has IO::Path:D $.ipkg
|
||||
|
@ -28,10 +29,42 @@ method title(--> Str:D) {
|
|||
# Use katla to highlight our file, mangle the resulting output, and then pass it
|
||||
# through to pandoc for html generation
|
||||
method render-html(--> Str:D) {
|
||||
# Do a pack build to make sure we have the needed files
|
||||
# TODO: Figure out how to only do this once
|
||||
|
||||
# Run through katla
|
||||
# Send output
|
||||
die "Not implemented";
|
||||
my $project-dir = $!ipkg.parent;
|
||||
indir $project-dir, {
|
||||
# Do a pack build to make sure we have the needed files
|
||||
# TODO: Figure out how to only do this once
|
||||
pack <build>;
|
||||
# First we have to find the location of the ttm file
|
||||
my $relative-path = $!source.extension('ttm').relative:
|
||||
$project-dir.add('src');
|
||||
my $ttc-dir = dir($project-dir.add('build/ttc/'))[0];
|
||||
my $ttm-path = $ttc-dir.add: $relative-path;
|
||||
# Run through katla
|
||||
my $output = katla 'markdown', $!source, $ttm-path;
|
||||
# Send output to pandoc through a temporary file
|
||||
my ($filename, $filehandle) = tempfile;
|
||||
$filehandle.spurt: $output, :close;
|
||||
markdown-to-html $filename.IO
|
||||
};
|
||||
}
|
||||
|
||||
# Run a pack command, erroring on failure
|
||||
sub pack(*@args) {
|
||||
my $pack = run 'pack', @args, :out, :err;
|
||||
my $pack-out = $pack.out.slurp: :close;
|
||||
my $pack-err = $pack.err.slurp: :close;
|
||||
die "Pack exited with {$pack.exitcode}\nout: $pack-out\nerr: $pack-err"
|
||||
unless $pack;
|
||||
}
|
||||
|
||||
# Run a katla command, erroring on failure, returning the standard out, and
|
||||
# mangling the output accordingly
|
||||
sub katla(*@args --> Str:D) {
|
||||
my $katla = run 'katla', @args, :out, :err;
|
||||
my $katla-out = $katla.out.slurp: :close;
|
||||
my $katla-err = $katla.err.slurp: :close;
|
||||
die "Katla exited with {$katla.exitcode}\nout: $katla-out\nerr: $katla-err"
|
||||
unless $katla;
|
||||
# TODO modify output
|
||||
$katla-out
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue