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?
|
#| Should the post be hidden from the archive?
|
||||||
Bool :$hidden = False,
|
Bool :$hidden = False,
|
||||||
) {
|
) {
|
||||||
say $default-ipkg;
|
|
||||||
my $db = read-db $db-dir;
|
my $db = read-db $db-dir;
|
||||||
my $id =
|
my $id =
|
||||||
$db.insert-post:
|
$db.insert-post:
|
||||||
|
|
|
@ -84,7 +84,10 @@ class PostDB {
|
||||||
my $id-path = $by-id.add: "$id.html";
|
my $id-path = $by-id.add: "$id.html";
|
||||||
$id-path.spurt: $html;
|
$id-path.spurt: $html;
|
||||||
for $post.all-slugs -> $slug {
|
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
|
# Render the archive
|
||||||
|
|
|
@ -2,6 +2,7 @@ use v6.e.PREVIEW;
|
||||||
|
|
||||||
use Pandoc;
|
use Pandoc;
|
||||||
use JSON::Class:auth<zef:vrurg>;
|
use JSON::Class:auth<zef:vrurg>;
|
||||||
|
use File::Temp;
|
||||||
|
|
||||||
use DB::Post;
|
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
|
#| Marker for disambiguation between post types in json representation, the
|
||||||
#| cheaty way
|
#| cheaty way
|
||||||
has Bool:D $.idris = True;
|
has Bool:D $.idris is json = True;
|
||||||
|
|
||||||
#| Location of the ipkg for the package containing the post
|
#| Location of the ipkg for the package containing the post
|
||||||
has IO::Path:D $.ipkg
|
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
|
# Use katla to highlight our file, mangle the resulting output, and then pass it
|
||||||
# through to pandoc for html generation
|
# through to pandoc for html generation
|
||||||
method render-html(--> Str:D) {
|
method render-html(--> Str:D) {
|
||||||
|
my $project-dir = $!ipkg.parent;
|
||||||
|
indir $project-dir, {
|
||||||
# Do a pack build to make sure we have the needed files
|
# Do a pack build to make sure we have the needed files
|
||||||
# TODO: Figure out how to only do this once
|
# 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
|
# Run through katla
|
||||||
# Send output
|
my $output = katla 'markdown', $!source, $ttm-path;
|
||||||
die "Not implemented";
|
# 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