Rendering template

This commit is contained in:
Nathan McCarty 2025-02-03 21:36:07 -05:00
parent abe676f512
commit 815ff4bf4e
3 changed files with 71 additions and 0 deletions

View file

@ -11,6 +11,7 @@ use DB::BlogMeta;
use DB::MarkdownPost;
use DB::IdrisPost;
use DB::PlaceholderPost;
use Config;
subset PostTypes where MarkdownPost:D | IdrisPost:D | PlaceholderPost:D;
@ -64,8 +65,36 @@ class PostDB {
$posts-dir.add("$key.json").spurt: $value.to-json;
}
}
#| Render the site to the provided output directory
method render(IO::Path:D $out-dir, Config:D :$config = Config.new) {
my $posts = $out-dir.add('posts/');
my $by-id = $posts.add('by-id/');
my $by-slug = $posts.add('by-slug/');
# Make sure the directory structure exists
mkdir $out-dir unless $out-dir.e;
mkdir $posts unless $posts.e;
mkdir $by-id unless $by-id.e;
mkdir $by-slug unless $by-slug.e;
# Render all the posts and make symlinks
for %!posts.kv -> $id, $post {
my $html =
$config.generate-post:
$post.title, $post.render-html, $!meta;
my $id-path = $by-id.add: "$id.html";
$id-path.spurt: $html;
for $post.all-slugs -> $slug {
$by-slug.add($slug).symlink: $id-path;
}
}
# Render the archive
# Render the rss/atom feed
# Render the index
die "Not Implemented"
}
}
#| Read the database out of a directory
sub read-db(IO::Path:D $dir --> PostDB:D) is export {
my $posts-dir = $dir.add('posts/');
die "DB directory does not exist" unless $dir.e;