Progress reporting for render command

This commit is contained in:
Nathan McCarty 2025-07-12 01:25:08 -04:00
parent 37022f7bdb
commit 5880e12b82
2 changed files with 14 additions and 2 deletions

2
blog
View file

@ -155,7 +155,7 @@ multi MAIN(
IO::Path(Str) :$site-dir = $default-site-dir,
) {
my $db = read-db $db-dir;
$db.render: $site-dir;
$db.render: $site-dir, :report;
}
#| Provide a table of posts, in newest to oldest order

View file

@ -96,7 +96,9 @@ class PostDB {
}
#| Render the site to the provided output directory
method render(IO::Path:D $out-dir, Config:D :$config = Config.new) {
method render(IO::Path:D $out-dir,
Config:D :$config = Config.new,
Bool :$report) {
## Consistency checks
# Check to make sure all the slugs are unique
my @all-the-slugs = %!posts.values.map(*.all-slugs).flat;
@ -113,6 +115,7 @@ class PostDB {
mkdir $by-slug unless $by-slug.e;
# Render all the posts and make symlinks
for %!posts.kv -> $id, $post {
say "Generating post $id: {$post.title}" when $report;
my $html = $config.generate-post: $id, $post, self;
my $id-path = $by-id.add: "$id.html";
$id-path.spurt: $html;
@ -124,10 +127,13 @@ class PostDB {
}
}
# Render the index
say "Rendering index" when $report;
$out-dir.add('index.html').spurt: $config.generate-index(self);
# Render the archive
say "Rendering archive" when $report;
$out-dir.add('archive.html').spurt: $config.generate-archive(self);
# Symlink the about article
say "Rendering the about article" when $report;
my $about-path = $out-dir.add('about.html');
$about-path.unlink if $about-path.l;
$by-id.add("{$!meta.about-id}.html").symlink: $about-path;
@ -137,6 +143,7 @@ class PostDB {
my $tags-dir = $out-dir.add('tags/');
mkdir $tags-dir unless $tags-dir.e;
for @tags -> $tag {
say "Rendering tags page: $tag" when $report;
$tags-dir.add("$tag.html").spurt:
$config.generate-tag-page(self, $tag);
}
@ -144,17 +151,21 @@ class PostDB {
my $series-dir = $out-dir.add('series/');
mkdir $series-dir unless $series-dir.e;
for %!series.kv -> $key, $value {
say "Rendering series page: $key" when $report;
$series-dir.add("$key.html").spurt:
series-page($key, self);
}
# Generate the main series page
say "Rendering main series list" when $report;
$out-dir.add('series.html').spurt:
series-list-page self;
# Render the rss/atom feed
say "Rendering atom feed" when $report;
my $atom-path = $out-dir.add('atom.xml');
my $atom = posts-to-atom self;
$atom-path.spurt: format-xml(~$atom);
# Create the resources folder and copy over our style sheets
say "Creating resources folder" when $report;
my $res-dir = $out-dir.add('resources/');
mkdir $res-dir unless $res-dir.e;
# symlink the resources directory to make "interactive" styling eaiser
@ -164,6 +175,7 @@ class PostDB {
%?RESOURCES<code.css>.IO.symlink: $res-dir.add('code.css') unless $res-dir.add('code.css').e;
%?RESOURCES<admonitions.css>.IO.symlink: $res-dir.add('admonitions.css') unless $res-dir.add('admonitions.css').e;
%?RESOURCES<cactus.css>.IO.symlink: $res-dir.add('cactus.css') unless $res-dir.add('cactus.css').e;
say "Done" when $report;
}
#| Get a list of posts sorted by date